18 using System.Collections.Generic;
21 namespace Deveel.Data.Store {
23 private const int Magic = 0x087131AA;
37 this.elementSize = elementSize;
38 blockElements =
new long[64];
39 blockAreas =
new IArea[64];
42 public int BlockCount {
get;
private set; }
44 public long NodeCount {
45 get {
return BlockFirstPosition(BlockCount); }
50 headerArea.WriteInt4(BlockCount);
52 for (
int i = 0; i < BlockCount; ++i) {
53 headerArea.WriteInt8(blockElements[i]);
60 IArea writer = store.CreateArea(528);
61 headerAreaId = writer.
Id;
62 writer.WriteInt4(Magic);
65 headerArea = store.GetArea(headerAreaId);
67 UpdateListHeaderArea();
72 public void Open(
long listPointer) {
73 headerAreaId = listPointer;
74 headerArea = store.GetArea(headerAreaId);
76 int magic = headerArea.ReadInt4();
78 throw new IOException(
"Incorrect magic for list block. [magic=" + magic +
"]");
80 BlockCount = headerArea.ReadInt4();
81 headerArea.ReadInt8();
82 for (
int i = 0; i < BlockCount; ++i) {
83 long blockPointer = headerArea.ReadInt8();
84 blockElements[i] = blockPointer;
85 blockAreas[i] = store.GetArea(blockPointer);
91 return headerArea.ReadInt8();
96 headerArea.WriteInt8(value);
103 long work = recordNumber + 32;
109 long startOffset = (1 << (bit - 1)) - 32;
110 int blockOffset = bit - 6;
111 long recordOffset = recordNumber - startOffset;
114 IArea blockArea = blockAreas[blockOffset];
115 blockArea.
Position = (int) (recordOffset*elementSize);
120 return 32L << blockNumber;
130 startIndex = startIndex + diff;
139 long sizeOfBlock = 32L << BlockCount;
142 var area = store.CreateArea(sizeOfBlock * elementSize);
143 var blockId = area.Id;
146 var blockArea = store.GetArea(blockId);
149 blockElements[BlockCount] = blockId;
150 blockAreas[BlockCount] = blockArea;
154 UpdateListHeaderArea();
160 store.DeleteArea(blockElements[BlockCount]);
163 blockAreas[BlockCount] = null;
164 blockElements[BlockCount] = 0;
167 UpdateListHeaderArea();
171 usedAreas.Add(headerAreaId);
172 for (
int i = 0; i < BlockCount; ++i) {
173 usedAreas.Add(blockElements[i]);
void Open(long listPointer)
void WriteDeleteHead(long value)
long BlockFirstPosition(int blockNumber)
long Position
Returns or sets the current position of the pointer within the area.
readonly long[] blockElements
void UpdateListHeaderArea()
void GetAreasUsed(IList< long > usedAreas)
FixedRecordList(IStore store, int elementSize)
An interface for access the contents of an area of a store.
long BlockNodeCount(int blockNumber)
readonly IArea[] blockAreas
long Id
Returns the unique identifier that represents this area.
A store is a resource where areas can be allocated and freed to store information (a memory allocator...
IArea GetRecord(long recordNumber)