Пример #1
0
        /// <summary>
        /// Opens a reader between each key
        /// </summary>
        /// <param name="LKey"></param>
        /// <param name="UKey"></param>
        /// <returns></returns>
        public virtual RecordReader OpenReader(Record LKey, Record UKey)
        {
            RecordKey l = this._Tree.FindFirstKey(LKey, false);
            RecordKey u = this._Tree.FindLastKey(UKey, false);

            return(new RecordReaderIndexData(this._Header, this._Storage, this._Parent, l, u));
        }
Пример #2
0
 public void Insert(Record Element, RecordKey Key)
 {
     for (int i = 0; i < this._Indexes.Count; i++)
     {
         this._Indexes[i].Insert(Element, Key);
     }
 }
Пример #3
0
        public override void Insert(Record Value)
        {
            if (this.State == TableState.ReadOnly || this.State == TableState.FullLock)
            {
                throw new Exception("Table is locked for writing");
            }

            // Handle the terminal page being full //
            if (!this._Terminis.CanAccept(Value))
            {
                Page p = new Page(this.PageSize, this.GenerateNewPageID, this._Terminis.PageID, -1, this.Columns.Count, 0);
                p.Version++;
                this._Header.PageCount++;
                this._Terminis.NextPageID = p.PageID;
                this.SetPage(p);
                this._Terminis = p;
                this._Header.TerminalPageID = p.PageID;
            }

            // Add the actual record //
            Value = this._Header.Columns.Fix(Value);
            this._Terminis.Insert(Value);
            this.RecordCount++;

            // Get the pointer //
            this._LastKey = new RecordKey(this._Terminis.PageID, this._Terminis.Count - 1);
            this._Indexes.Insert(Value, this._LastKey);

            // Step the version //
            this._Version++;
        }
Пример #4
0
        public override Record Read()
        {
            Record    v = base.Read();
            RecordKey x = new RecordKey(v[this._Header.PointerIndex]);

            //RecordKey y = base.PositionKey;
            return(this._Parent.GetPage(x.PAGE_ID).Select(x.ROW_ID));
        }
Пример #5
0
        /// <summary>
        /// Opens a record reader that focuses on a single key
        /// </summary>
        /// <param name="Key"></param>
        /// <returns></returns>
        public override RecordReader OpenReader(Record Key)
        {
            if (Key.Count != this._Cluster.Comparer.Count)
            {
                return(this.OpenReader());
            }
            RecordKey l = this._Cluster.FindFirstKey(Key, false);
            RecordKey u = this._Cluster.FindLastKey(Key, false);

            return(new RecordReaderBase(this, l, u));
        }
Пример #6
0
        /// <summary>
        /// Opens a reader, but if the key is not found, it will return null
        /// </summary>
        /// <param name="Key"></param>
        /// <returns></returns>
        public virtual RecordReader OpenStrictReader(Record Key)
        {
            RecordKey l = this._Tree.FindFirstKey(Key, true);
            RecordKey u = this._Tree.FindLastKey(Key, true);

            if (l.IsNotFound || u.IsNotFound)
            {
                return(null);
            }
            return(new RecordReaderIndexData(this._Header, this._Storage, this._Parent, l, u));
        }
Пример #7
0
        /// <summary>
        /// Opens a record reader to focus on records between A and B (inclusive)
        /// </summary>
        /// <param name="LKey"></param>
        /// <param name="UKey"></param>
        /// <returns></returns>
        public override RecordReader OpenReader(Record LKey, Record UKey)
        {
            if (LKey.Count != UKey.Count || LKey.Count != this._Cluster.Comparer.Count)
            {
                return(this.OpenReader());
            }
            RecordKey lk = this._Cluster.FindFirstKey(LKey, false);
            RecordKey uk = this._Cluster.FindLastKey(UKey, false);

            return(new RecordReaderBase(this, lk, uk));
        }
Пример #8
0
        /// <summary>
        /// Attempts to select a record, if it fails to find the record, returns null
        /// </summary>
        /// <param name="Position"></param>
        /// <returns></returns>
        public virtual Record TrySelect(RecordKey Position)
        {
            if (this._Header.PageCount <= Position.PAGE_ID)
            {
                return(null);
            }

            Page p = this.GetPage(Position.PAGE_ID);

            if (Position.ROW_ID >= p.Count)
            {
                return(null);
            }

            return(p.Select(Position.ROW_ID));
        }
Пример #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Composite"></param>
        public void SetValue(Record Composite)
        {
            // Step the version //
            this._Version++;

            // If exists, then update, otherwise add
            RecordKey ptr = this._Cluster.FindFirst(Composite, true);

            if (ptr.IsNotFound)
            {
                this.Insert(Composite);
            }
            else
            {
                this._Cluster.Update(ptr, Composite);
            }
        }
Пример #10
0
        /// <summary>
        /// Calibrates the index
        /// </summary>
        public virtual void Calibrate()
        {
            if (this._Header.RecordCount != 0 || this._Parent.RecordCount == 0)
            {
                return;
            }

            RecordReader stream = this._Parent.OpenReader();

            while (stream.CanAdvance)
            {
                RecordKey rk  = stream.PositionKey;
                Record    rec = stream.ReadNext();

                this.Insert(rec, rk);
            }
        }
Пример #11
0
 public RecordReaderBase(Table Data, RecordKey LKey, RecordKey UKey)
     : base()
 {
     this._Lower   = LKey;
     this._Upper   = UKey;
     this._Storage = Data;
     if (this._Storage.PageCount == 0)
     {
         this._CurrentPage        = null;
         this._CurrentPageID      = -1;
         this._CurrentRecordIndex = -1;
     }
     else
     {
         this._CurrentPage        = this._Storage.GetPage(this._Lower.PAGE_ID);
         this._CurrentPageID      = this._CurrentPage.PageID;
         this._CurrentRecordIndex = this._Lower.ROW_ID;
     }
 }
Пример #12
0
        /// <summary>
        /// Sets a value
        /// </summary>
        /// <param name="Key"></param>
        /// <param name="AWValue"></param>
        public void SetValue(Record Key, Record Value)
        {
            // Step the version //
            this._Version++;

            // Get the final record value //
            Record r = Record.Join(Key, Value);

            // If exists, then update, otherwise add
            RecordKey ptr = this._Cluster.FindFirstKey(Key, true);

            if (ptr.IsNotFound)
            {
                this.Insert(r);
            }
            else
            {
                this._Cluster.Update(ptr, r);
            }
        }
Пример #13
0
        /// <summary>
        /// Gets a record, invluding the key and value
        /// </summary>
        /// <param name="Key"></param>
        /// <returns></returns>
        public Record GetKeyValue2(Record Composite)
        {
            // Check the last key first //
            if (this._LastKey != null)
            {
                if (Record.Compare(Record.Split(Composite, this._KeyFields), this._LastKey) == 0)
                {
                    return(this._Cluster.Storage.GetPage(this._LastRef.PAGE_ID).Select(this._LastRef.ROW_ID));
                }
            }

            // Get the record key //
            RecordKey x = this._Cluster.FindFirst(Composite, true);

            // This should really only trigger if the table is empty; actually, this should never trigger //
            if (x.IsNotFound)
            {
                return(null);
            }

            // Select the record, and if it's null, return //
            Record y = this._Cluster.Storage.TrySelect(x);

            if (y == null)
            {
                return(null);
            }

            // Need to check if we didn't find the actual record //
            if (Record.Compare(y, Composite, this._KeyFields) == 0)
            {
                this._LastRef = x;
                this._LastKey = Record.Split(Composite, this._KeyFields);
                return(y);
            }

            // Not found //
            return(null);
        }
Пример #14
0
 /// <summary>
 /// Opens an indexed reader
 /// </summary>
 /// <param name="Header">The index header</param>
 /// <param name="Storage">The table that stores the index pages</param>
 /// <param name="Parent">The table that stores the data pages; may be the same object as 'Storage'</param>
 /// <param name="LKey">The lower bound key</param>
 /// <param name="RKey">The upper bound key</param>
 public RecordReaderIndexData(IndexHeader Header, Table Storage, Table Parent, RecordKey LKey, RecordKey RKey)
     : base(Storage, LKey, RKey)
 {
     this._Header = Header;
     this._Parent = Parent;
 }
Пример #15
0
 /// <summary>
 /// Gets a record from a table
 /// </summary>
 /// <param name="Position"></param>
 /// <returns></returns>
 public virtual Record Select(RecordKey Position)
 {
     return(this.GetPage(Position.PAGE_ID).Select(Position.ROW_ID));
 }
Пример #16
0
 public RecordReaderIndexKey(IndexHeader Header, Table Storage, RecordKey LKey, RecordKey RKey)
     : base(Storage, LKey, RKey)
 {
     this._Header = Header;
 }
Пример #17
0
 // Methods //
 public override void Insert(Record Element, RecordKey Key)
 {
     // Note: key is ignored here
     this._Parent.Insert(Element);
 }
Пример #18
0
        // Statics //
        /// <summary>
        /// Creates the (Key, Pointer) record
        /// </summary>
        /// <param name="Key"></param>
        /// <param name="Pointer"></param>
        /// <param name="IndexColumns"></param>
        /// <returns></returns>
        public static Record GetIndexElement(Record Element, RecordKey Pointer, Key IndexColumns)
        {
            Record t = (Element * IndexColumns) + Pointer.Element;

            return(t);
        }
Пример #19
0
 public static RecordKey Min(RecordKey A, RecordKey B)
 {
     return(A < B ? A : B);
 }
Пример #20
0
 public static RecordKey Max(RecordKey A, RecordKey B)
 {
     return(A > B ? A : B);
 }
Пример #21
0
        // Methods //
        /// <summary>
        /// Inserts a record into the index
        /// </summary>
        /// <param name="Key">The record</param>
        /// <param name="Key">The position it's located in the table</param>
        public virtual void Insert(Record Element, RecordKey Key)
        {
            Record x = TreeIndex.GetIndexElement(Element, Key, this._IndexColumns);

            this._Tree.Insert(x);
        }