18 using System.Collections.Generic;
24 namespace Deveel.Data.Index {
35 this.indexSetStore = indexSetStore;
36 this.indexNum = indexNum;
37 BlockSize = blockSize;
38 StartOffset = startOffset;
41 var indexBlockArea = indexSetStore.
Store.
GetArea(startOffset);
43 blockEntries = indexBlockArea.ReadInt8();
50 public bool IsFreed {
get;
private set; }
52 public bool IsDeleted {
get;
private set; }
54 public int BlockSize {
get;
private set; }
56 public long StartOffset {
get;
private set; }
60 var indexBlockArea = indexSetStore.Store.GetArea(StartOffset);
63 long[] blocks =
new long[(int)blockEntries];
64 if (blockEntries != 0) {
65 indexBlockArea.Position = 16;
67 for (
int i = 0; i < blockEntries; ++i) {
69 indexBlockArea.ReadInt8();
70 indexBlockArea.ReadInt8();
71 long elementP = indexBlockArea.ReadInt8();
72 indexBlockArea.ReadInt4();
83 var indexBlockArea = indexSetStore.Store.GetArea(StartOffset);
87 if (blockEntries != 0) {
88 indexBlockArea.Position = 16;
89 for (
int i = 0; i < blockEntries; ++i) {
91 var firstEntry = indexBlockArea.ReadInt8();
92 var lastEntry = indexBlockArea.ReadInt8();
93 var blockPointer = indexBlockArea.ReadInt8();
94 var typeSize = indexBlockArea.ReadInt4();
98 int elementCount = typeSize & 0x0FFF;
113 return new StoreIndex(indexSetStore, indexNum, BlockSize, blocks);
117 bool parentDeleted =
true;
118 if (Parent != null) {
119 parentDeleted = Parent.DeleteBlockChain();
129 if (IsDeleted && deletedAreas != null) {
130 indexSetStore.DeleteAreas(deletedAreas);
139 return parentDeleted;
145 throw new Exception(
"Assertion failed: Block was freed.");
152 bool pendingDelete =
false;
157 throw new Exception(
"Assertion failed: remove reference called too many times.");
159 if (!IsDeleted && deletedAreas != null)
160 throw new Exception(
"Assertion failed: not deleted and with deleted areas");
165 AddDeletedArea(StartOffset);
167 pendingDelete =
true;
173 lock (indexSetStore.Store) {
187 if (deletedAreas == null) {
188 deletedAreas =
new List<int>();
191 deletedAreas.Add((
int)pointer);
readonly IndexSetStore indexSetStore
long Position
Returns or sets the current position of the pointer within the area.
static IMappedBlock NewMappedBlock(IndexSetStore indexSetStore, long firstEntry, long lastEntry, long blockPointer, int size, byte compactType, int blockSize)
IndexBlock(IndexSetStore indexSetStore, int indexNum, int blockSize, long startOffset)
readonly long blockEntries
static int URShift(int number, int bits)
Operates a shift on the given integer by the number of bits specified.
An interface for querying and accessing an index of primitive integers.
A wrapper for an array of byte.
long[] GetBlockPointers()
IEnumerable< IMappedBlock > CreateMappedBlocks()
void AddDeletedArea(long pointer)
IArea GetArea(long id, bool readOnly)
Returns an object that allows for the contents of an area (represented by the id parameter) to be Re...