Ejemplo n.º 1
0
        internal int GetRecord(DataRow row)
        {
            int index = Key.GetRecord(row, _rowStateFilter);

            if (_filter == null)
            {
                return(index);
            }

            if (index < 0)
            {
                return(index);
            }

            return(CanContain(index) ? index : -1);
        }
Ejemplo n.º 2
0
 private void RebuildIndex()
 {
     // consider better capacity approximation
     _array = new int [Key.Table.RecordCache.CurrentCapacity];
     _size  = 0;
     foreach (DataRow row in Key.Table.Rows)
     {
         int record = Key.GetRecord(row);
         if (record != -1)
         {
             _array [_size++] = record;
         }
     }
     _hasDuplicates = IndexDuplicatesState.False;
     // Note : MergeSort may update hasDuplicates to True
     Sort();
 }
Ejemplo n.º 3
0
        private void RebuildIndex()
        {
            int rows_upperbound = Key.Table.RecordCache.CurrentCapacity;

            if (rows_upperbound == 0)
            {
                return;
            }

            // consider better capacity approximation
            _array = new int [rows_upperbound];
            _size  = 0;
            foreach (DataRow row in Key.Table.Rows)
            {
                int record = Key.GetRecord(row);
                if (record != -1)
                {
                    _array [_size++] = record;
                }
            }
            know_have_duplicates = know_no_duplicates = false;
            Sort();
            know_no_duplicates = !know_have_duplicates;
        }
Ejemplo n.º 4
0
 internal void Add(DataRow row)
 {
     Add(row, Key.GetRecord(row));
 }
Ejemplo n.º 5
0
        internal void Update(DataRow row, int oldRecord, DataRowVersion oldVersion, DataRowState oldState)
        {
            bool contains  = Key.ContainsVersion(oldState, oldVersion);
            int  newRecord = Key.GetRecord(row);

            // the record did not appeared in the index before update
            if (oldRecord == -1 || _size == 0 || !contains)
            {
                if (newRecord >= 0)
                {
                    if (FindIndexExact(newRecord) < 0)
                    {
                        Add(row, newRecord);
                    }
                }
                return;
            }

            // the record will not appeare in the index after update
            if (newRecord < 0 || !Key.CanContain(newRecord))
            {
                Delete(oldRecord);
                return;
            }

            int oldIdx = FindIndexExact(oldRecord);

            if (oldIdx == -1)
            {
                Add(row, newRecord);
                return;
            }

            int newIdx = -1;
            int compare = Key.CompareRecords(_array [oldIdx], newRecord);
            int start, end;

            int c1 = 1;
            int c2 = 1;

            if (compare == 0)
            {
                if (_array [oldIdx] == newRecord)
                {
                    // we deal with the same record that didn't change
                    // in the context of current index.
                    // so , do nothing.
                    return;
                }
            }
            else
            {
                if (know_have_duplicates)
                {
                    if (oldIdx > 0)
                    {
                        c1 = Key.CompareRecords(_array [oldIdx - 1], newRecord);
                    }
                    if (oldIdx < _size - 1)
                    {
                        c2 = Key.CompareRecords(_array [oldIdx + 1], newRecord);
                    }

                    if ((c1 == 0 ^ c2 == 0) && compare != 0)
                    {
                        know_have_duplicates = know_no_duplicates = false;
                    }
                }
            }

            if ((oldIdx == 0 && compare > 0) || (oldIdx == (_size - 1) && compare < 0) || (compare == 0))
            {
                // no need to switch cells
                newIdx = oldIdx;
            }
            else
            {
                if (compare < 0)
                {
                    // search after the old place
                    start = oldIdx + 1;
                    end   = _size - 1;
                }
                else
                {
                    // search before the old palce
                    start = 0;
                    end   = oldIdx - 1;
                }

                newIdx = LazyBinarySearch(_array, start, end, newRecord);

                if (oldIdx < newIdx)
                {
                    System.Array.Copy(_array, oldIdx + 1, _array, oldIdx, newIdx - oldIdx);
                    if (Key.CompareRecords(_array [newIdx], newRecord) > 0)
                    {
                        --newIdx;
                    }
                }
                else if (oldIdx > newIdx)
                {
                    System.Array.Copy(_array, newIdx, _array, newIdx + 1, oldIdx - newIdx);
                    if (Key.CompareRecords(_array [newIdx], newRecord) < 0)
                    {
                        ++newIdx;
                    }
                }
            }
            _array[newIdx] = newRecord;

            if (compare != 0)
            {
                if (!know_have_duplicates)
                {
                    if (newIdx > 0)
                    {
                        c1 = Key.CompareRecords(_array [newIdx - 1], newRecord);
                    }
                    if (newIdx < _size - 1)
                    {
                        c2 = Key.CompareRecords(_array [newIdx + 1], newRecord);
                    }

                    if (c1 == 0 || c2 == 0)
                    {
                        know_have_duplicates = true;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        internal void Delete(DataRow row)
        {
            int oldRecord = Key.GetRecord(row);

            Delete(oldRecord);
        }