DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Classes | Public Member Functions | Protected Member Functions | Properties | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
Deveel.Data.Index.BlockIndex< T >.Block Class Reference
Inheritance diagram for Deveel.Data.Index.BlockIndex< T >.Block:
Deveel.Data.Index.IIndexBlock< T >

Classes

class  Enumerator
 

Public Member Functions

 Block (int blockSize)
 
IEnumerator< T > GetEnumerator ()
 
bool CanContain (int number)
 
void Add (T value)
 Adss an int element to the block. More...
 
RemoveAt (int index)
 Removes the element at the given index from the block. More...
 
int IndexOf (T value)
 summary> Performs an iterative search from the given position to the end of the list in the block. /summary> param name="value"> More...
 
int IndexOf (T value, int startIndex)
 
void Insert (T value, int index)
 Inserts an element to the block at the given index. More...
 
void MoveTo (IIndexBlock< T > destBlock, int destIndex, int length)
 summary> Copies all the data from this block into the given destination block. /summary> param name="destBlock"> More...
 
void CopyTo (IIndexBlock< T > destBlock)
 summary> Copies all the data from this block into the given array. /summary> param name="array">The destination array of the copy. More...
 
int CopyTo (T[] destArray, int arrayIndex)
 
void Clear ()
 Clears the block of all elements. More...
 
int BinarySearch (object key, IIndexComparer< T > comparer)
 summary> Finds the first index in the block that equals the given key. /summary> param name="key"> More...
 
int SearchFirst (object key, IIndexComparer< T > comparer)
 summary> Finds the last index in the block that equals the given key. /summary> param name="key"> More...
 
int SearchLast (object key, IIndexComparer< T > comparer)
 summary> Assuming a sorted block, finds the first index in the block that equals the given value. /summary> param name="value"> More...
 
int SearchFirst (T value)
 summary> Assuming a sorted block, finds the last index in the block that equals the given value. /summary> param name="value"> More...
 
int SearchLast (T value)
 

Protected Member Functions

 Block ()
 
virtual T[] GetArray (bool readOnly)
 

Properties

T[] BaseArray [get, set]
 
virtual int ArrayLength [get]
 
IIndexBlock< T > IIndexBlock< T >. Next [get, set]
 
Block Next [get, set]
 
IIndexBlock< T > IIndexBlock< T >. Previous [get, set]
 
Block Previous [get, set]
 
bool HasChanged [get]
 
int Count [get, protected set]
 
bool IsFull [get]
 
bool IsEmpty [get]
 
virtual T Top [get]
 
virtual T Bottom [get]
 
this[int index] [get, set]
 
- Properties inherited from Deveel.Data.Index.IIndexBlock< T >
IIndexBlock< T > Next [get, set]
 Gets or sets the next block in the hash. More...
 
IIndexBlock< T > Previous [get, set]
 Gets or sets the previous block in the hash. More...
 
bool HasChanged [get]
 
int Count [get]
 
bool IsFull [get]
 Gets a value indicating if the block is full. More...
 
bool IsEmpty [get]
 Gets a value indicating if the block is empty. More...
 
Top [get]
 Gets the element at the top of the block. More...
 
Bottom [get]
 Gets the element at the bottom of the block. More...
 
this[int index] [get, set]
 Gets or sets the element at the given index within the block. More...
 

Private Member Functions

IEnumerator IEnumerable. GetEnumerator ()
 

Static Private Member Functions

static bool IsSmallerOrEqual (T x, T y)
 
static bool IsGreaterOrEqual (T x, T y)
 
static bool IsGreater (T x, T y)
 
static bool IsSmaller (T x, T y)
 

Private Attributes

int count
 
bool changed
 

Detailed Description

Definition at line 59 of file BlockIndex_T.cs.

Constructor & Destructor Documentation

Deveel.Data.Index.BlockIndex< T >.Block.Block ( )
inlineprotected

Definition at line 63 of file BlockIndex_T.cs.

63  {
64  }
Deveel.Data.Index.BlockIndex< T >.Block.Block ( int  blockSize)
inline

Definition at line 66 of file BlockIndex_T.cs.

67  : this() {
68  BaseArray = new T[blockSize];
69  count = 0;
70  }

Member Function Documentation

void Deveel.Data.Index.BlockIndex< T >.Block.Add ( value)
inline

Adss an int element to the block.

Implements Deveel.Data.Index.IIndexBlock< T >.

Definition at line 176 of file BlockIndex_T.cs.

176  {
177  changed = true;
178  var arr = GetArray(false);
179  arr[count] = value;
180  ++count;
181  }
virtual T[] GetArray(bool readOnly)
int Deveel.Data.Index.BlockIndex< T >.Block.BinarySearch ( object  key,
IIndexComparer< T >  comparer 
)
inline

summary> Finds the first index in the block that equals the given key. /summary> param name="key">

Implements Deveel.Data.Index.IIndexBlock< T >.

Definition at line 267 of file BlockIndex_T.cs.

267  {
268  var arr = GetArray(true);
269  int low = 0;
270  int high = count - 1;
271 
272  while (low <= high) {
273  int mid = (low + high)/2;
274  int cmp = comparer.CompareValue(arr[mid], (DataObject) key);
275 
276  if (cmp < 0)
277  low = mid + 1;
278  else if (cmp > 0)
279  high = mid - 1;
280  else
281  return mid; // key found
282  }
283  return -(low + 1); // key not found.
284  }
virtual T[] GetArray(bool readOnly)
bool Deveel.Data.Index.BlockIndex< T >.Block.CanContain ( int  number)
inline

Implements Deveel.Data.Index.IIndexBlock< T >.

Definition at line 171 of file BlockIndex_T.cs.

171  {
172  return count + number + 1 < ArrayLength;
173  }
void Deveel.Data.Index.BlockIndex< T >.Block.Clear ( )
inline

Clears the block of all elements.

Implements Deveel.Data.Index.IIndexBlock< T >.

Definition at line 261 of file BlockIndex_T.cs.

261  {
262  changed = true;
263  count = 0;
264  }
void Deveel.Data.Index.BlockIndex< T >.Block.CopyTo ( IIndexBlock< T >  destBlock)
inline

summary> Copies all the data from this block into the given array. /summary> param name="array">The destination array of the copy.

Implements Deveel.Data.Index.IIndexBlock< T >.

Definition at line 246 of file BlockIndex_T.cs.

246  {
247  var block = (Block) destBlock;
248  var destArr = block.GetArray(false);
249  Array.Copy(GetArray(true), 0, destArr, 0, count);
250  block.count = count;
251  block.changed = true;
252  }
virtual T[] GetArray(bool readOnly)
int Deveel.Data.Index.BlockIndex< T >.Block.CopyTo ( T[]  destArray,
int  arrayIndex 
)
inline

Implements Deveel.Data.Index.IIndexBlock< T >.

Definition at line 255 of file BlockIndex_T.cs.

255  {
256  Array.Copy(GetArray(true), 0, destArray, arrayIndex, count);
257  return count;
258  }
virtual T[] GetArray(bool readOnly)
virtual T [] Deveel.Data.Index.BlockIndex< T >.Block.GetArray ( bool  readOnly)
inlineprotectedvirtual

Definition at line 145 of file BlockIndex_T.cs.

145  {
146  if (readOnly) {
147  var newArray = new T[BaseArray.Length];
148  Array.Copy(BaseArray, 0, newArray, 0, BaseArray.Length);
149  return newArray;
150  }
151  return BaseArray;
152  }
IEnumerator<T> Deveel.Data.Index.BlockIndex< T >.Block.GetEnumerator ( )
inline

Definition at line 78 of file BlockIndex_T.cs.

78  {
79  return new Enumerator(this);
80  }
IEnumerator IEnumerable. Deveel.Data.Index.BlockIndex< T >.Block.GetEnumerator ( )
inlineprivate

Definition at line 82 of file BlockIndex_T.cs.

82  {
83  return GetEnumerator();
84  }
IEnumerator< T > GetEnumerator()
Definition: BlockIndex_T.cs:78
int Deveel.Data.Index.BlockIndex< T >.Block.IndexOf ( value)
inline

summary> Performs an iterative search from the given position to the end of the list in the block. /summary> param name="value">

Implements Deveel.Data.Index.IIndexBlock< T >.

Definition at line 194 of file BlockIndex_T.cs.

194  {
195  var arr = GetArray(true);
196  for (int i = count - 1; i >= 0; --i) {
197  if (arr[i].Equals(value))
198  return i;
199  }
200  return -1;
201  }
virtual T[] GetArray(bool readOnly)
int Deveel.Data.Index.BlockIndex< T >.Block.IndexOf ( value,
int  startIndex 
)
inline

Implements Deveel.Data.Index.IIndexBlock< T >.

Definition at line 204 of file BlockIndex_T.cs.

204  {
205  var arr = GetArray(true);
206  for (int i = startIndex; i < count; ++i) {
207  if (arr[i].Equals(value))
208  return i;
209  }
210  return -1;
211  }
virtual T[] GetArray(bool readOnly)
void Deveel.Data.Index.BlockIndex< T >.Block.Insert ( value,
int  index 
)
inline

Inserts an element to the block at the given index.

Implements Deveel.Data.Index.IIndexBlock< T >.

Definition at line 214 of file BlockIndex_T.cs.

214  {
215  changed = true;
216  var arr = GetArray(false);
217  Array.Copy(BaseArray, index, arr, index + 1, (count - index));
218  ++count;
219  arr[index] = value;
220  }
virtual T[] GetArray(bool readOnly)
static bool Deveel.Data.Index.BlockIndex< T >.Block.IsGreater ( x,
y 
)
inlinestaticprivate

Definition at line 162 of file BlockIndex_T.cs.

162  {
163  return x.CompareTo(y) > 0;
164  }
static bool Deveel.Data.Index.BlockIndex< T >.Block.IsGreaterOrEqual ( x,
y 
)
inlinestaticprivate

Definition at line 158 of file BlockIndex_T.cs.

158  {
159  return x.CompareTo(y) >= 0;
160  }
static bool Deveel.Data.Index.BlockIndex< T >.Block.IsSmaller ( x,
y 
)
inlinestaticprivate

Definition at line 166 of file BlockIndex_T.cs.

166  {
167  return x.CompareTo(y) < 0;
168  }
static bool Deveel.Data.Index.BlockIndex< T >.Block.IsSmallerOrEqual ( x,
y 
)
inlinestaticprivate

Definition at line 154 of file BlockIndex_T.cs.

154  {
155  return x.CompareTo(y) <= 0;
156  }
void Deveel.Data.Index.BlockIndex< T >.Block.MoveTo ( IIndexBlock< T >  destBlock,
int  destIndex,
int  length 
)
inline

summary> Copies all the data from this block into the given destination block. /summary> param name="destBlock">

Implements Deveel.Data.Index.IIndexBlock< T >.

Definition at line 223 of file BlockIndex_T.cs.

223  {
224  var block = (Block) destBlock;
225 
226  var arr = GetArray(false);
227  var destArr = block.GetArray(false);
228 
229  // Make room in the destination block
230  int destbSize = block.Count;
231  if (destbSize > 0) {
232  Array.Copy(destArr, 0, destArr, length, destbSize);
233  }
234 
235  // Copy from this block into the destination block.
236  Array.Copy(arr, count - length, destArr, 0, length);
237  // Alter size of destination and source block.
238  block.count += length;
239  count -= length;
240  // Mark both blocks as changed
241  changed = true;
242  block.changed = true;
243  }
virtual T[] GetArray(bool readOnly)
T Deveel.Data.Index.BlockIndex< T >.Block.RemoveAt ( int  index)
inline

Removes the element at the given index from the block.

Implements Deveel.Data.Index.IIndexBlock< T >.

Definition at line 184 of file BlockIndex_T.cs.

184  {
185  changed = true;
186  var arr = GetArray(false);
187  var val = arr[index];
188  Array.Copy(BaseArray, index + 1, arr, index, (count - index));
189  --count;
190  return val;
191  }
virtual T[] GetArray(bool readOnly)
int Deveel.Data.Index.BlockIndex< T >.Block.SearchFirst ( object  key,
IIndexComparer< T >  comparer 
)
inline

summary> Finds the last index in the block that equals the given key. /summary> param name="key">

Implements Deveel.Data.Index.IIndexBlock< T >.

Definition at line 287 of file BlockIndex_T.cs.

287  {
288  var arr = GetArray(true);
289  int low = 0;
290  int high = count - 1;
291 
292  while (low <= high) {
293  if (high - low <= 2) {
294  for (int i = low; i <= high; ++i) {
295  int cmp1 = comparer.CompareValue(arr[i], (DataObject) key);
296  if (cmp1 == 0)
297  return i;
298 
299  if (cmp1 > 0)
300  return -(i + 1);
301  }
302 
303  return -(high + 2);
304  }
305 
306  int mid = (low + high)/2;
307  int cmp = comparer.CompareValue(arr[mid], (DataObject) key);
308 
309  if (cmp < 0) {
310  low = mid + 1;
311  } else if (cmp > 0) {
312  high = mid - 1;
313  } else {
314  high = mid;
315  }
316  }
317  return -(low + 1); // key not found.
318 
319  }
virtual T[] GetArray(bool readOnly)
int Deveel.Data.Index.BlockIndex< T >.Block.SearchFirst ( value)
inline

summary> Assuming a sorted block, finds the last index in the block that equals the given value. /summary> param name="value">

Implements Deveel.Data.Index.IIndexBlock< T >.

Definition at line 355 of file BlockIndex_T.cs.

355  {
356  var arr = GetArray(true);
357  int low = 0;
358  int high = count - 1;
359 
360  while (low <= high) {
361 
362  if (high - low <= 2) {
363  for (int i = low; i <= high; ++i) {
364  if (arr[i].Equals(value))
365  return i;
366  if (IsGreater(arr[i], value))
367  return -(i + 1);
368  }
369  return -(high + 2);
370  }
371 
372  int mid = (low + high)/2;
373 
374  if (IsSmaller(arr[mid], value)) {
375  low = mid + 1;
376  } else if (IsGreater(arr[mid], value)) {
377  high = mid - 1;
378  } else {
379  high = mid;
380  }
381  }
382  return -(low + 1); // key not found.
383  }
static bool IsGreater(T x, T y)
static bool IsSmaller(T x, T y)
virtual T[] GetArray(bool readOnly)
int Deveel.Data.Index.BlockIndex< T >.Block.SearchLast ( object  key,
IIndexComparer< T >  comparer 
)
inline

summary> Assuming a sorted block, finds the first index in the block that equals the given value. /summary> param name="value">

Implements Deveel.Data.Index.IIndexBlock< T >.

Definition at line 322 of file BlockIndex_T.cs.

322  {
323  var arr = GetArray(true);
324  int low = 0;
325  int high = count - 1;
326 
327  while (low <= high) {
328 
329  if (high - low <= 2) {
330  for (int i = high; i >= low; --i) {
331  int cmp1 = comparer.CompareValue(arr[i], (DataObject) key);
332  if (cmp1 == 0)
333  return i;
334  if (cmp1 < 0)
335  return -(i + 2);
336  }
337  return -(low + 1);
338  }
339 
340  int mid = (low + high)/2;
341  int cmp = comparer.CompareValue(arr[mid], (DataObject) key);
342 
343  if (cmp < 0) {
344  low = mid + 1;
345  } else if (cmp > 0) {
346  high = mid - 1;
347  } else {
348  low = mid;
349  }
350  }
351  return -(low + 1); // key not found.
352  }
virtual T[] GetArray(bool readOnly)
int Deveel.Data.Index.BlockIndex< T >.Block.SearchLast ( value)
inline

Implements Deveel.Data.Index.IIndexBlock< T >.

Definition at line 386 of file BlockIndex_T.cs.

386  {
387  var arr = GetArray(true);
388  int low = 0;
389  int high = count - 1;
390 
391  while (low <= high) {
392 
393  if (high - low <= 2) {
394  for (int i = high; i >= low; --i) {
395  if (arr[i].Equals(value))
396  return i;
397  if (IsSmaller(arr[i], value))
398  return -(i + 2);
399  }
400  return -(low + 1);
401  }
402 
403  int mid = (low + high)/2;
404 
405  if (IsSmaller(arr[mid], value)) {
406  low = mid + 1;
407  } else if (IsGreater(arr[mid], value)) {
408  high = mid - 1;
409  } else {
410  low = mid;
411  }
412  }
413  return -(low + 1); // key not found.
414  }
static bool IsGreater(T x, T y)
static bool IsSmaller(T x, T y)
virtual T[] GetArray(bool readOnly)

Member Data Documentation

bool Deveel.Data.Index.BlockIndex< T >.Block.changed
private

Definition at line 61 of file BlockIndex_T.cs.

int Deveel.Data.Index.BlockIndex< T >.Block.count
private

Definition at line 60 of file BlockIndex_T.cs.

Property Documentation

virtual int Deveel.Data.Index.BlockIndex< T >.Block.ArrayLength
getprotected

Definition at line 74 of file BlockIndex_T.cs.

T [] Deveel.Data.Index.BlockIndex< T >.Block.BaseArray
getsetprotected

Definition at line 72 of file BlockIndex_T.cs.

virtual T Deveel.Data.Index.BlockIndex< T >.Block.Bottom
get

Definition at line 127 of file BlockIndex_T.cs.

int Deveel.Data.Index.BlockIndex< T >.Block.Count
getprotected set

Definition at line 106 of file BlockIndex_T.cs.

bool Deveel.Data.Index.BlockIndex< T >.Block.HasChanged
get

Definition at line 101 of file BlockIndex_T.cs.

bool Deveel.Data.Index.BlockIndex< T >.Block.IsEmpty
get

Definition at line 117 of file BlockIndex_T.cs.

bool Deveel.Data.Index.BlockIndex< T >.Block.IsFull
get

Definition at line 112 of file BlockIndex_T.cs.

IIndexBlock<T> IIndexBlock<T>. Deveel.Data.Index.BlockIndex< T >.Block.Next
getsetprivate

Definition at line 86 of file BlockIndex_T.cs.

Block Deveel.Data.Index.BlockIndex< T >.Block.Next
getsetprivate

Definition at line 91 of file BlockIndex_T.cs.

IIndexBlock<T> IIndexBlock<T>. Deveel.Data.Index.BlockIndex< T >.Block.Previous
getsetprivate

Definition at line 93 of file BlockIndex_T.cs.

Block Deveel.Data.Index.BlockIndex< T >.Block.Previous
getsetprivate

Definition at line 98 of file BlockIndex_T.cs.

T Deveel.Data.Index.BlockIndex< T >.Block.this[int index]
getset

Definition at line 137 of file BlockIndex_T.cs.

virtual T Deveel.Data.Index.BlockIndex< T >.Block.Top
get

Definition at line 122 of file BlockIndex_T.cs.


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