DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Properties | Private Member Functions | Private Attributes | List of all members
Deveel.Data.Store.FixedRecordList Class Reference

Public Member Functions

 FixedRecordList (IStore store, int elementSize)
 
long Create ()
 
void Open (long listPointer)
 
long ReadDeleteHead ()
 
void WriteDeleteHead (long value)
 
IArea GetRecord (long recordNumber)
 
long BlockNodeCount (int blockNumber)
 
long BlockFirstPosition (int blockNumber)
 
void IncreaseSize ()
 
void DecreaseSize ()
 
void GetAreasUsed (IList< long > usedAreas)
 

Properties

int BlockCount [get, private set]
 
long NodeCount [get]
 

Private Member Functions

void UpdateListHeaderArea ()
 

Private Attributes

const int Magic = 0x087131AA
 
readonly IStore store
 
readonly int elementSize
 
long headerAreaId
 
IArea headerArea
 
readonly long[] blockElements
 
readonly IArea[] blockAreas
 

Detailed Description

Definition at line 22 of file FixedRecordList.cs.

Constructor & Destructor Documentation

Deveel.Data.Store.FixedRecordList.FixedRecordList ( IStore  store,
int  elementSize 
)
inline

Definition at line 35 of file FixedRecordList.cs.

35  {
36  this.store = store;
37  this.elementSize = elementSize;
38  blockElements = new long[64];
39  blockAreas = new IArea[64];
40  }

Member Function Documentation

long Deveel.Data.Store.FixedRecordList.BlockFirstPosition ( int  blockNumber)
inline

Definition at line 123 of file FixedRecordList.cs.

123  {
124  // For example, this first node of block 0 is 0, the first node of block 1 is
125  // 32, the first node of block 2 is 96, etc.
126  long startIndex = 0;
127  int i = blockNumber;
128  long diff = 32;
129  while (i > 0) {
130  startIndex = startIndex + diff;
131  diff = diff << 1;
132  --i;
133  }
134  return startIndex;
135  }
long Deveel.Data.Store.FixedRecordList.BlockNodeCount ( int  blockNumber)
inline

Definition at line 119 of file FixedRecordList.cs.

119  {
120  return 32L << blockNumber;
121  }
long Deveel.Data.Store.FixedRecordList.Create ( )
inline

Definition at line 58 of file FixedRecordList.cs.

58  {
59  // Allocate space for the list header (8 + 8 + (64 * 8))
60  IArea writer = store.CreateArea(528);
61  headerAreaId = writer.Id;
62  writer.WriteInt4(Magic);
63  writer.Flush();
64 
66  BlockCount = 0;
68 
69  return headerAreaId;
70  }
IArea CreateArea(long size)
Allocates a block of memory in the store of the specified size and returns an IArea object that can b...
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...
void Deveel.Data.Store.FixedRecordList.DecreaseSize ( )
inline

Definition at line 157 of file FixedRecordList.cs.

157  {
158  --BlockCount;
159  // Free the top block
161 
162  // Help the GC
163  blockAreas[BlockCount] = null;
165 
166  // Update the list header.
168  }
void DeleteArea(long id)
Deletes an area that was previously allocated by the CreateArea method by the area id...
void Deveel.Data.Store.FixedRecordList.GetAreasUsed ( IList< long >  usedAreas)
inline

Definition at line 170 of file FixedRecordList.cs.

170  {
171  usedAreas.Add(headerAreaId);
172  for (int i = 0; i < BlockCount; ++i) {
173  usedAreas.Add(blockElements[i]);
174  }
175  }
IArea Deveel.Data.Store.FixedRecordList.GetRecord ( long  recordNumber)
inline

Definition at line 100 of file FixedRecordList.cs.

100  {
101  // What block is this record in?
102  int bit = 0;
103  long work = recordNumber + 32;
104  while (work != 0) {
105  work = work >> 1;
106  ++bit;
107  }
108 
109  long startOffset = (1 << (bit - 1)) - 32;
110  int blockOffset = bit - 6;
111  long recordOffset = recordNumber - startOffset;
112 
113  // Get the pointer to the block that contains this record status
114  IArea blockArea = blockAreas[blockOffset];
115  blockArea.Position = (int) (recordOffset*elementSize);
116  return blockArea;
117  }
long Position
Returns or sets the current position of the pointer within the area.
Definition: IArea.cs:48
void Deveel.Data.Store.FixedRecordList.IncreaseSize ( )
inline

Definition at line 137 of file FixedRecordList.cs.

137  {
138  // The size of the block
139  long sizeOfBlock = 32L << BlockCount;
140 
141  // Allocate the new block in the store
142  var area = store.CreateArea(sizeOfBlock * elementSize);
143  var blockId = area.Id;
144  area.Flush();
145 
146  var blockArea = store.GetArea(blockId);
147 
148  // Update the block list
149  blockElements[BlockCount] = blockId;
150  blockAreas[BlockCount] = blockArea;
151  ++BlockCount;
152 
153  // Update the list header,
155  }
IArea CreateArea(long size)
Allocates a block of memory in the store of the specified size and returns an IArea object that can b...
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...
long Id
Returns the unique identifier that represents this area.
Definition: IArea.cs:31
void Deveel.Data.Store.FixedRecordList.Open ( long  listPointer)
inline

Definition at line 72 of file FixedRecordList.cs.

72  {
73  headerAreaId = listPointer;
75 
76  int magic = headerArea.ReadInt4(); // MAGIC
77  if (magic != Magic)
78  throw new IOException("Incorrect magic for list block. [magic=" + magic + "]");
79 
80  BlockCount = headerArea.ReadInt4();
81  headerArea.ReadInt8(); // Delete Chain Head
82  for (int i = 0; i < BlockCount; ++i) {
83  long blockPointer = headerArea.ReadInt8();
84  blockElements[i] = blockPointer;
85  blockAreas[i] = store.GetArea(blockPointer);
86  }
87  }
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...
long Deveel.Data.Store.FixedRecordList.ReadDeleteHead ( )
inline

Definition at line 89 of file FixedRecordList.cs.

89  {
90  headerArea.Position = 8;
91  return headerArea.ReadInt8();
92  }
long Position
Returns or sets the current position of the pointer within the area.
Definition: IArea.cs:48
void Deveel.Data.Store.FixedRecordList.UpdateListHeaderArea ( )
inlineprivate

Definition at line 48 of file FixedRecordList.cs.

48  {
49  headerArea.Position = 4;
50  headerArea.WriteInt4(BlockCount);
51  headerArea.Position = 16;
52  for (int i = 0; i < BlockCount; ++i) {
53  headerArea.WriteInt8(blockElements[i]);
54  }
55  headerArea.Flush();
56  }
long Position
Returns or sets the current position of the pointer within the area.
Definition: IArea.cs:48
void Deveel.Data.Store.FixedRecordList.WriteDeleteHead ( long  value)
inline

Definition at line 94 of file FixedRecordList.cs.

94  {
95  headerArea.Position = 8;
96  headerArea.WriteInt8(value);
97  headerArea.Flush();
98  }
long Position
Returns or sets the current position of the pointer within the area.
Definition: IArea.cs:48

Member Data Documentation

readonly IArea [] Deveel.Data.Store.FixedRecordList.blockAreas
private

Definition at line 33 of file FixedRecordList.cs.

readonly long [] Deveel.Data.Store.FixedRecordList.blockElements
private

Definition at line 32 of file FixedRecordList.cs.

readonly int Deveel.Data.Store.FixedRecordList.elementSize
private

Definition at line 26 of file FixedRecordList.cs.

IArea Deveel.Data.Store.FixedRecordList.headerArea
private

Definition at line 29 of file FixedRecordList.cs.

long Deveel.Data.Store.FixedRecordList.headerAreaId
private

Definition at line 28 of file FixedRecordList.cs.

const int Deveel.Data.Store.FixedRecordList.Magic = 0x087131AA
private

Definition at line 23 of file FixedRecordList.cs.

readonly IStore Deveel.Data.Store.FixedRecordList.store
private

Definition at line 25 of file FixedRecordList.cs.

Property Documentation

int Deveel.Data.Store.FixedRecordList.BlockCount
getprivate set

Definition at line 42 of file FixedRecordList.cs.

long Deveel.Data.Store.FixedRecordList.NodeCount
get

Definition at line 44 of file FixedRecordList.cs.


The documentation for this class was generated from the following file: