private Index(DataTable table, IndexField[] indexFields, System.Comparison <DataRow> comparison, DataViewRowState recordStates, IFilter rowFilter) { DataCommonEventSource.Log.Trace("<ds.Index.Index|API> {0}, table={1}, recordStates={2}", ObjectID, (table != null) ? table.ObjectID : 0, recordStates); Debug.Assert(indexFields != null); Debug.Assert(null != table, "null table"); if ((recordStates & (~(DataViewRowState.CurrentRows | DataViewRowState.OriginalRows))) != 0) { throw ExceptionBuilder.RecordStateRange(); } _table = table; _listeners = new Listeners <DataViewListener>(ObjectID, listener => null != listener); _indexFields = indexFields; _recordStates = recordStates; _comparison = comparison; DataColumnCollection columns = table.Columns; _isSharable = (rowFilter == null) && (comparison == null); // a filter or comparison make an index unsharable if (null != rowFilter) { _rowFilter = new WeakReference(rowFilter); DataExpression expr = (rowFilter as DataExpression); if (null != expr) { _hasRemoteAggregate = expr.HasRemoteAggregate(); } } InitRecords(rowFilter); // do not AddRef in ctor, every caller should be responsible to AddRef it // if caller does not AddRef, it is expected to be a one-time read operation because the index won't be maintained on writes }
private Index(DataTable table, int[] ndexDesc, IndexField[] indexFields, Comparison<DataRow> comparison, DataViewRowState recordStates, IFilter rowFilter) { this._objectID = Interlocked.Increment(ref _objectTypeCount); Bid.Trace("<ds.Index.Index|API> %d#, table=%d, recordStates=%d{ds.DataViewRowState}\n", this.ObjectID, (table != null) ? table.ObjectID : 0, (int) recordStates); if ((recordStates & ~(DataViewRowState.OriginalRows | DataViewRowState.ModifiedCurrent | DataViewRowState.Added)) != DataViewRowState.None) { throw ExceptionBuilder.RecordStateRange(); } this.table = table; this._listeners = new Listeners<DataViewListener>(this.ObjectID, listener => null != listener); this.IndexDesc = ndexDesc; this.IndexFields = indexFields; if (ndexDesc == null) { this.IndexDesc = Select.ConvertIndexFieldtoIndexDesc(indexFields); } this.recordStates = recordStates; this._comparison = comparison; DataColumnCollection columns = table.Columns; this.isSharable = (rowFilter == null) && (comparison == null); if (rowFilter != null) { this.rowFilter = new WeakReference(rowFilter); DataExpression expression = rowFilter as DataExpression; if (expression != null) { this._hasRemoteAggregate = expression.HasRemoteAggregate(); } } this.InitRecords(rowFilter); }