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

Public Member Functions

 RangeChecker (BlindSearchIndex scheme, IndexRange[] ranges)
 
IEnumerable< int > Resolve ()
 Resolves the ranges. More...
 

Private Member Functions

void ResolveSortedSet ()
 
DataObject ResolveCell (DataObject ob)
 Resolves a cell. More...
 
void SetupRange (int i, IndexRange range)
 Set up a range. More...
 

Private Attributes

readonly BlindSearchIndex scheme
 
IEnumerable< int > sortedSet
 The sorted list of all items in the set created as a cache for finding the first and last values. More...
 
readonly byte[] lowerFlags
 
readonly byte[] upperFlags
 
readonly DataObject[] lowerCells
 
readonly DataObject[] upperCells
 
const byte NoCheck = 0
 
const byte CheckLesserOrGreater = 1
 
const byte CheckLesserEqualOrGreaterEqual = 2
 

Detailed Description

Definition at line 111 of file BlindSearchIndex.cs.

Constructor & Destructor Documentation

Deveel.Data.Index.BlindSearchIndex.RangeChecker.RangeChecker ( BlindSearchIndex  scheme,
IndexRange[]  ranges 
)
inline

Definition at line 133 of file BlindSearchIndex.cs.

133  {
134  this.scheme = scheme;
135 
136  int size = ranges.Length;
137  lowerFlags = new byte[size];
138  upperFlags = new byte[size];
139  lowerCells = new DataObject[size];
140  upperCells = new DataObject[size];
141  for (int i = 0; i < ranges.Length; ++i) {
142  SetupRange(i, ranges[i]);
143  }
144  }
void SetupRange(int i, IndexRange range)
Set up a range.

Member Function Documentation

IEnumerable<int> Deveel.Data.Index.BlindSearchIndex.RangeChecker.Resolve ( )
inline

Resolves the ranges.

Returns

Definition at line 220 of file BlindSearchIndex.cs.

220  {
221  // The idea here is to only need to scan the column once to find all
222  // the cells that meet our criteria.
223  var list = new List<int>();
224  var e = scheme.Table.GetEnumerator();
225 
226  int compareTally = 0;
227 
228  int size = lowerFlags.Length;
229  while (e.MoveNext()) {
230  int row = e.Current.RowId.RowNumber;
231  // For each range
232  for (int i = 0; i < size; ++i) {
233  bool result = true;
234  byte lf = lowerFlags[i];
235  if (lf != NoCheck) {
236  ++compareTally;
237  var v = scheme.GetValue(row);
238  int compare = lowerCells[i].CompareTo(v);
239  if (lf == CheckLesserOrGreater) { // >
240  result = (compare < 0);
241  } else if (lf == CheckLesserEqualOrGreaterEqual) { // >=
242  result = (compare <= 0);
243  } else {
244  throw new InvalidOperationException("Incorrect flag.");
245  }
246  }
247  if (result) {
248  byte uf = upperFlags[i];
249  if (uf != NoCheck) {
250  ++compareTally;
251  var v = scheme.GetValue(row);
252  int compare = upperCells[i].CompareTo(v);
253  if (uf == CheckLesserOrGreater) { // <
254  result = (compare > 0);
255  } else if (uf == CheckLesserEqualOrGreaterEqual) { // >=
256  result = (compare >= 0);
257  } else {
258  throw new InvalidOperationException("Incorrect flag.");
259  }
260  }
261  // Pick this row
262  if (result) {
263  scheme.DoInsertSort(list, row);
264  break;
265  }
266  }
267  }
268  }
269 
270  return list.AsEnumerable();
271  }
int CompareTo(DataObject other)
Definition: DataObject.cs:131
DataObject GetValue(long row)
Definition: ColumnIndex.cs:60
void DoInsertSort(IList< int > list, int row)
DataObject Deveel.Data.Index.BlindSearchIndex.RangeChecker.ResolveCell ( DataObject  ob)
inlineprivate

Resolves a cell.

Parameters
ob
Returns

Definition at line 157 of file BlindSearchIndex.cs.

157  {
158  if (ob.Equals(IndexRange.FirstInSet)) {
160  return scheme.GetValue(sortedSet.First());
161 
162  }
163  if (ob.Equals(IndexRange.LastInSet)) {
165  return scheme.GetValue(sortedSet.Last());
166  }
167 
168  return ob;
169  }
IEnumerable< int > sortedSet
The sorted list of all items in the set created as a cache for finding the first and last values...
DataObject GetValue(long row)
Definition: ColumnIndex.cs:60
void Deveel.Data.Index.BlindSearchIndex.RangeChecker.ResolveSortedSet ( )
inlineprivate

Definition at line 146 of file BlindSearchIndex.cs.

146  {
147  if (sortedSet == null) {
149  }
150  }
override IEnumerable< int > SelectAll()
IEnumerable< int > sortedSet
The sorted list of all items in the set created as a cache for finding the first and last values...
void Deveel.Data.Index.BlindSearchIndex.RangeChecker.SetupRange ( int  i,
IndexRange  range 
)
inlineprivate

Set up a range.

Parameters
i
range

Definition at line 176 of file BlindSearchIndex.cs.

176  {
177  var l = range.StartValue;
178  var lf = range.StartOffset;
179  var u = range.EndValue;
180  var uf = range.EndOffset;
181 
182  // Handle lower first
183  if (l.Equals(IndexRange.FirstInSet) &&
184  lf.Equals(RangeFieldOffset.FirstValue)) {
185  // Special case no lower check
186  lowerFlags[i] = NoCheck;
187  } else {
188  if (lf.Equals(RangeFieldOffset.FirstValue)) {
190  } else if (lf.Equals(RangeFieldOffset.AfterLastValue)) {
192  } else {
193  throw new InvalidOperationException("Incorrect lower flag.");
194  }
195  lowerCells[i] = ResolveCell(l);
196  }
197 
198  // Now handle upper
199  if (u.Equals(IndexRange.LastInSet) &&
200  uf.Equals(RangeFieldOffset.LastValue)) {
201  // Special case no upper check
202  upperFlags[i] = NoCheck;
203  } else {
204  if (uf.Equals(RangeFieldOffset.LastValue)) {
206  } else if (uf.Equals( RangeFieldOffset.BeforeFirstValue)) {
208  } else {
209  throw new InvalidOperationException("Incorrect upper flag.");
210  }
211  upperCells[i] = ResolveCell(u);
212  }
213 
214  }
DataObject ResolveCell(DataObject ob)
Resolves a cell.
RangeFieldOffset
The absolute offset of a field in a range of a selection.

Member Data Documentation

const byte Deveel.Data.Index.BlindSearchIndex.RangeChecker.CheckLesserEqualOrGreaterEqual = 2
private

Definition at line 131 of file BlindSearchIndex.cs.

const byte Deveel.Data.Index.BlindSearchIndex.RangeChecker.CheckLesserOrGreater = 1
private

Definition at line 130 of file BlindSearchIndex.cs.

readonly DataObject [] Deveel.Data.Index.BlindSearchIndex.RangeChecker.lowerCells
private

Definition at line 126 of file BlindSearchIndex.cs.

readonly byte [] Deveel.Data.Index.BlindSearchIndex.RangeChecker.lowerFlags
private

Definition at line 122 of file BlindSearchIndex.cs.

const byte Deveel.Data.Index.BlindSearchIndex.RangeChecker.NoCheck = 0
private

Definition at line 129 of file BlindSearchIndex.cs.

readonly BlindSearchIndex Deveel.Data.Index.BlindSearchIndex.RangeChecker.scheme
private

Definition at line 112 of file BlindSearchIndex.cs.

IEnumerable<int> Deveel.Data.Index.BlindSearchIndex.RangeChecker.sortedSet
private

The sorted list of all items in the set created as a cache for finding the first and last values.

Definition at line 118 of file BlindSearchIndex.cs.

readonly DataObject [] Deveel.Data.Index.BlindSearchIndex.RangeChecker.upperCells
private

Definition at line 127 of file BlindSearchIndex.cs.

readonly byte [] Deveel.Data.Index.BlindSearchIndex.RangeChecker.upperFlags
private

Definition at line 123 of file BlindSearchIndex.cs.


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