18 using System.Collections.Generic;
27 : base(table, columnOffset) {
30 public override string IndexType {
36 throw new ArgumentException(
"Cannot mutate a read-only index.");
40 if ((higher - lower) <= 5) {
42 for (var i = higher; i >= lower; --i) {
43 int res = ob.
CompareTo(GetValue(list[i]));
51 var mid = (lower + higher)/2;
52 int compResult = ob.
CompareTo(GetValue(list[mid]));
56 return HighestSearch(ob, list, mid, higher);
59 return HighestSearch(ob, list, lower, mid - 1);
61 return HighestSearch(ob, list, mid + 1, higher);
65 int listSize = list.Count;
69 var point = HighestSearch(GetValue(row), list, 0, listSize - 1);
70 if (point == listSize) {
73 list.Insert(point, row);
82 public override void Insert(
int rowNumber) {
86 public override void Remove(
int rowNumber) {
94 return new List<int>(0);
97 return checker.Resolve();
103 while (e.MoveNext()) {
104 DoInsertSort(rowList, e.Current.RowId.RowNumber);
129 private const byte NoCheck = 0;
130 private const byte CheckLesserOrGreater = 1;
131 private const byte CheckLesserEqualOrGreaterEqual = 2;
134 this.scheme = scheme;
136 int size = ranges.Length;
137 lowerFlags =
new byte[size];
138 upperFlags =
new byte[size];
141 for (
int i = 0; i < ranges.Length; ++i) {
142 SetupRange(i, ranges[i]);
147 if (sortedSet == null) {
148 sortedSet = scheme.SelectAll();
160 return scheme.GetValue(sortedSet.First());
165 return scheme.GetValue(sortedSet.Last());
186 lowerFlags[i] = NoCheck;
189 lowerFlags[i] = CheckLesserEqualOrGreaterEqual;
191 lowerFlags[i] = CheckLesserOrGreater;
193 throw new InvalidOperationException(
"Incorrect lower flag.");
195 lowerCells[i] = ResolveCell(l);
202 upperFlags[i] = NoCheck;
205 upperFlags[i] = CheckLesserEqualOrGreaterEqual;
207 upperFlags[i] = CheckLesserOrGreater;
209 throw new InvalidOperationException(
"Incorrect upper flag.");
211 upperCells[i] = ResolveCell(u);
223 var list =
new List<int>();
224 var e = scheme.Table.GetEnumerator();
226 int compareTally = 0;
228 int size = lowerFlags.Length;
229 while (e.MoveNext()) {
230 int row = e.Current.RowId.RowNumber;
232 for (
int i = 0; i < size; ++i) {
234 byte lf = lowerFlags[i];
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);
244 throw new InvalidOperationException(
"Incorrect flag.");
248 byte uf = upperFlags[i];
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);
258 throw new InvalidOperationException(
"Incorrect flag.");
263 scheme.DoInsertSort(list, row);
270 return list.AsEnumerable();
readonly byte[] lowerFlags
Defines the contract to access the data contained into a table of a database.
readonly BlindSearchIndex scheme
override ColumnIndex Copy(ITable table, bool readOnly)
override bool Equals(object obj)
IEnumerable< int > Resolve()
Resolves the ranges.
Describes the range of values to select from an index.
DataObject ResolveCell(DataObject ob)
Resolves a cell.
DataObject EndValue
Gets the last value of the range.
abstract IEnumerator< Row > GetEnumerator()
override void Insert(int rowNumber)
static readonly DataObject FirstInSet
RangeFieldOffset EndOffset
Gets the offset of the last value of the range.
readonly byte[] upperFlags
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...
BlindSearchIndex(ITable table, int columnOffset)
int CompareTo(DataObject other)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
DataObject StartValue
Gets the first value of the range.
readonly DataObject[] lowerCells
RangeChecker(BlindSearchIndex scheme, IndexRange[] ranges)
static readonly DataObject LastInSet
void SetupRange(int i, IndexRange range)
Set up a range.
override IEnumerable< int > SelectRange(IndexRange[] ranges)
RangeFieldOffset
The absolute offset of a field in a range of a selection.
readonly DataObject[] upperCells
void DoInsertSort(IList< int > list, int row)
override void Remove(int rowNumber)
int HighestSearch(DataObject ob, IList< int > list, int lower, int higher)
RangeFieldOffset StartOffset
Gets the offset of the first value of the range.