Index.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* ---------------------------------------------------------------------------
  2. Nullsoft Database Engine
  3. --------------------
  4. codename: Near Death Experience
  5. --------------------------------------------------------------------------- */
  6. /* ---------------------------------------------------------------------------
  7. Raw Index Class Prototypes
  8. --------------------------------------------------------------------------- */
  9. #ifndef __RAWINDEX_H
  10. #define __RAWINDEX_H
  11. #include <stdio.h>
  12. #ifdef WIN32
  13. #include <io.h>
  14. #else
  15. #include <unistd.h>
  16. #endif
  17. #include "vfs.h"
  18. #include "Table.h"
  19. class IndexField;
  20. #define BLOCK_SIZE 2048 // 8192 entries blocks
  21. class RecordBase;
  22. class Index
  23. {
  24. public:
  25. Index(VFILE *Handle, unsigned char id, int pos, int type, bool newindex, int nentries, Table *parentTable);
  26. ~Index();
  27. int Get(int Idx);
  28. void Set(int Idx, int P);
  29. void LoadIndex(bool newindex);
  30. void WriteIndex(void);
  31. int Insert(Index *parindex, int N, bool localonly);
  32. int Insert(int N);
  33. int Update(int Idx, int Pos, RecordBase *record, bool localonly);
  34. int Update(Index *parindex, int paridx, int Idx, int Pos, RecordBase *record, bool forceLast, bool localonly);
  35. unsigned char GetId();
  36. int FindSortedPlace(Field *field, int idx, int *laststate, int start);
  37. int FindSortedPlaceEx(Field *field, int idx, int *laststate, int start, int comp_mode);
  38. int MoveIndex(int idx, int newidx);
  39. void Colaborate(IndexField *secindex);
  40. void SetCooperative(int Idx, int secpos);
  41. int GetCooperative(int Idx);
  42. void UpdateMe(Index *Me, int newidx, int oldidx);
  43. Field *QuickFindField(unsigned char Id, int Pos);
  44. int QuickFind(int Id, Field *field, int start);
  45. int QuickFindEx(int Id, Field *field, int start, int comp_mode);
  46. int TranslateIndex(int Pos, Index *index);
  47. void Delete(int Idx, int Pos, Record *record);
  48. void Shrink(void);
  49. void Propagate(void);
  50. void SetGlobalLocateUpToDate(bool isUptodate);
  51. int NeedFix();
  52. public:
  53. // TODO: make these protected
  54. int NEntries;
  55. IndexField *SecIndex;
  56. bool locateUpToDate;
  57. protected:
  58. VFILE *Handle;
  59. VFILE *TableHandle;
  60. Table *pTable;
  61. int *IndexTable;
  62. size_t MaxSize;
  63. unsigned char Id;
  64. bool InChain;
  65. int Position;
  66. bool InInsert;
  67. int InChainIdx;
  68. };
  69. #endif