18 using System.Collections.Generic;
24 namespace Deveel.Data.Index {
30 ColumnOffset = columnOffset;
40 EmptyList.IsReadOnly =
true;
43 OneList.IsReadOnly =
true;
48 public int ColumnOffset {
get;
private set; }
50 public virtual bool IsReadOnly {
54 public virtual bool HandlesTextSearch {
58 public abstract string IndexType {
get; }
68 GC.SuppressFinalize(
this);
71 protected virtual void Dispose(
bool disposing) {
74 public abstract void Insert(
int rowNumber);
76 public abstract void Remove(
int rowNumber);
79 var rowSet = rows.ToList();
82 int rowSetLength = rowSet.Count;
86 if (rowSetLength == 0)
88 if (rowSetLength == 1)
95 if (rowSetLength <= 250000) {
100 var subsetList =
new List<DataObject>(rowSetLength);
101 foreach (
long row
in rowSet) {
102 subsetList.Add(GetValue(row));
109 for (
int i = 0; i < rowSetLength; ++i) {
110 var cell = subsetList[i];
111 newSet.InsertSort(cell, i, comparer);
121 for (
int i = 0; i < rowSetLength; ++i) {
122 var cell = GetValue(rowSet[i]);
123 newSet.InsertSort(cell, i, comparer);
131 return SelectRange(
new[] {range});
134 public abstract IEnumerable<int> SelectRange(
IndexRange[] ranges);
182 return new List<int>(0);
191 return new List<int>(0);
206 return new List<int>(0);
215 return new List<int>(0);
224 return new List<int>(0);
233 return new List<int>(0);
242 return new List<int>(0);
251 return new List<int>(0);
253 if (!HandlesTextSearch)
254 return SelectEqual(value);
256 return SearchText(value);
260 throw new NotSupportedException(
"The column index does not support text search.");
264 if (subsetTable == null)
265 throw new ArgumentNullException(
"subsetTable");
268 List<int> rowSet =
new List<int>(subsetTable.
RowCount);
269 var e = subsetTable.GetEnumerator();
270 while (e.MoveNext()) {
271 rowSet.Add(e.Current.RowId.RowNumber);
274 var rows = subsetTable.ResolveRows(subsetColumn, rowSet,
Table);
278 var newSet = Order(rows);
281 if (newSet.Count != rowSet.Count) {
282 throw new Exception(
"Internal sort error in finding sub-set.");
285 return CreateSubset(subsetTable, subsetColumn, newSet);
290 index.RecordUid =
false;
294 #region IndexComparer
298 private readonly IEnumerable<int>
rowSet;
301 this.scheme = scheme;
302 this.rowSet = rowSet;
306 var cell = scheme.GetValue(rowSet.ElementAt((
int)index));
307 return cell.CompareTo(val);
311 throw new NotSupportedException(
"Shouldn't be called!");
317 #region SubsetIndexComparer
323 this.subsetList = subsetList;
327 var cell = subsetList[index];
328 return cell.CompareTo(val);
332 throw new NotSupportedException(
"Shouldn't be called!");
IEnumerable< int > SelectEqual(DataObject ob)
virtual IEnumerable< int > SelectFirst()
readonly IEnumerable< int > rowSet
abstract DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
int CompareValue(int index, DataObject val)
bool IsNull
Gets a value that indicates if this object is materialized as null.
Defines the contract to access the data contained into a table of a database.
IndexComparer(ColumnIndex scheme, IEnumerable< int > rowSet)
IEnumerable< int > SelectGreaterOrEqual(DataObject ob)
SubsetIndexComparer(DataObject[] subsetList)
IEnumerable< int > SelectLast()
Describes the range of values to select from an index.
A comparer that is used within IIndex to compares two values which are indices to data that is bei...
static DataObject Null(SqlType type)
IEnumerable< int > SelectNotFirst()
readonly ColumnIndex scheme
static readonly DataObject FirstInSet
IIndex< int > Order(IEnumerable< int > rows)
virtual IEnumerable< int > SearchText(DataObject value)
IEnumerable< int > SelectNotLast()
int CompareValue(int index, DataObject val)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
DataObject GetValue(long row)
IEnumerable< int > SelectRange(IndexRange range)
int RowCount
Gets the total number of rows in the table.
int Compare(int index1, int index2)
static readonly BlockIndex< int > OneList
IEnumerable< int > SelectGreater(DataObject ob)
IEnumerable< int > SelectBetween(DataObject ob1, DataObject ob2)
readonly DataObject[] subsetList
static readonly BlockIndex< int > EmptyList
IEnumerable< int > SelectLess(DataObject ob)
int Compare(int index1, int index2)
ColumnIndex(ITable table, int columnOffset)
static readonly DataObject LastInSet
IEnumerable< int > SelectNotEqual(DataObject ob)
virtual ColumnIndex CreateSubset(ITable table, int column, IEnumerable< int > rows)
IEnumerable< int > SelectLessOrEqual(DataObject ob)
RangeFieldOffset
The absolute offset of a field in a range of a selection.
IEnumerable< int > SelectLike(DataObject value)
virtual IEnumerable< int > SelectAll()
virtual void Dispose(bool disposing)
virtual ColumnIndex GetSubset(ITable subsetTable, int subsetColumn)
IEnumerable< int > SelectAllNonNull()