예제 #1
0
        public void Put(T obj, int mask)
        {
            DatabaseImpl db = (DatabaseImpl)Database;

            if (db == null)
            {
                throw new DatabaseException(DatabaseException.ErrorCode.DELETED_OBJECT);
            }
            if (!obj.IsPersistent())
            {
                db.MakePersistent(obj);
            }
            Key ins = new Key(mask, obj.Oid);

            if (root == 0)
            {
                root   = BitIndexPage.allocate(db, 0, ins);
                height = 1;
            }
            else
            {
                OldBtreeResult result = BitIndexPage.insert(db, root, ins, height);
                if (result == OldBtreeResult.Overflow)
                {
                    root    = BitIndexPage.allocate(db, root, ins);
                    height += 1;
                }
            }
            updateCounter += 1;
            nElems        += 1;
            Modify();
        }
        public void Put(object obj, int mask)
#endif
        {
            StorageImpl db = (StorageImpl)Storage;

            if (db == null)
            {
                throw new StorageError(StorageError.ErrorCode.DELETED_OBJECT);
            }
            Key ins = new Key(mask, db.MakePersistent(obj));

            if (root == 0)
            {
                root   = BitIndexPage.allocate(db, 0, ins);
                height = 1;
            }
            else
            {
                BtreeResult result = BitIndexPage.insert(db, root, ins, height);
                if (result == BtreeResult.Overflow)
                {
                    root    = BitIndexPage.allocate(db, root, ins);
                    height += 1;
                }
            }
            updateCounter += 1;
            nElems        += 1;
            Modify();
        }
예제 #3
0
        public int Get(T obj)
        {
            DatabaseImpl db = (DatabaseImpl)Database;

            if (root == 0)
            {
                throw new DatabaseException(DatabaseException.ErrorCode.KEY_NOT_FOUND);
            }
            return(BitIndexPage.find(db, root, obj.Oid, height));
        }
            public bool MoveNext()
            {
                if (counter != index.updateCounter)
                {
                    throw new InvalidOperationException("B-Tree was modified");
                }
                if (sp == 0)
                {
                    return(false);
                }
                int  pos = posStack[sp - 1];
                Page pg  = db.getPage(pageStack[sp - 1]);

                do
                {
                    int end = BitIndexPage.getnItems(pg);

                    while (pos < end)
                    {
                        int mask = BitIndexPage.getItem(pg, pos);
                        pos += 1;
                        if ((setBits & mask) == setBits && (clearBits & mask) == 0)
                        {
                            posStack[sp - 1] = pos;
                            db.pool.unfix(pg);
                            return(true);
                        }
                    }

                    while (--sp != 0)
                    {
                        db.pool.unfix(pg);
                        pos = posStack[sp - 1];
                        pg  = db.getPage(pageStack[sp - 1]);
                        if (++pos <= BitIndexPage.getnItems(pg))
                        {
                            posStack[sp - 1] = pos;
                            do
                            {
                                int pageId = BitIndexPage.getItem(pg, BitIndexPage.maxItems - 1 - pos);
                                db.pool.unfix(pg);
                                pg            = db.getPage(pageId);
                                pageStack[sp] = pageId;
                                posStack[sp]  = pos = 0;
                            } while (++sp < pageStack.Length);
                            break;
                        }
                    }
                } while (sp != 0);

                db.pool.unfix(pg);
                return(false);
            }
            private object getCurrent()
            {
                if (sp == 0)
                {
                    throw new InvalidOperationException();
                }
                int    pos  = posStack[sp - 1];
                Page   pg   = db.getPage(pageStack[sp - 1]);
                object curr = db.lookupObject(BitIndexPage.getItem(pg, BitIndexPage.maxItems - pos), null);

                db.pool.unfix(pg);
                return(curr);
            }
        new public int Get(object obj)
#endif
        {
            StorageImpl db = (StorageImpl)Storage;

            if (root == 0)
            {
                throw new StorageError(StorageError.ErrorCode.KEY_NOT_FOUND);
            }
#if USE_GENERICS
            return(BitIndexPage.find(db, root, db.GetOid(obj), height));
#else
            return(BitIndexPage.find(db, root, db.GetOid(obj), height));
#endif
        }
            public void Reset()
            {
                sp = 0;
                int h      = index.height;
                int pageId = index.root;

                while (--h >= 0)
                {
                    pageStack[sp] = pageId;
                    posStack[sp]  = 0;
                    Page pg = db.getPage(pageId);
                    sp    += 1;
                    pageId = BitIndexPage.getItem(pg, BitIndexPage.maxItems - 1);
                    db.pool.unfix(pg);
                }
            }
        public bool Remove(object obj)
#endif
        {
            StorageImpl db = (StorageImpl)Storage;

            if (db == null)
            {
                throw new StorageError(StorageError.ErrorCode.DELETED_OBJECT);
            }
            if (root == 0)
            {
                return(false);
            }
            BtreeResult result = BitIndexPage.remove(db, root, db.GetOid(obj), height);

            if (result == BtreeResult.NotFound)
            {
                return(false);
            }
            nElems -= 1;
            if (result == BtreeResult.Underflow)
            {
                Page pg = db.getPage(root);
                if (BitIndexPage.getnItems(pg) == 0)
                {
                    int newRoot = 0;
                    if (height != 1)
                    {
                        newRoot = BitIndexPage.getItem(pg, BitIndexPage.maxItems - 1);
                    }
                    db.freePage(root);
                    root    = newRoot;
                    height -= 1;
                }
                db.pool.unfix(pg);
            }
            updateCounter += 1;
            Modify();
            return(true);
        }
예제 #9
0
        public override bool Remove(T obj)
        {
            DatabaseImpl db = (DatabaseImpl)Database;

            if (db == null)
            {
                throw new DatabaseException(DatabaseException.ErrorCode.DELETED_OBJECT);
            }
            if (root == 0)
            {
                return(false);
            }
            OldBtreeResult result = BitIndexPage.remove(db, root, obj.Oid, height);

            if (result == OldBtreeResult.NotFound)
            {
                return(false);
            }
            nElems -= 1;
            if (result == OldBtreeResult.Underflow)
            {
                Page pg = db.getPage(root);
                if (BitIndexPage.getnItems(pg) == 0)
                {
                    int newRoot = 0;
                    if (height != 1)
                    {
                        newRoot = BitIndexPage.getItem(pg, BitIndexPage.maxItems - 1);
                    }
                    db.freePage(root);
                    root    = newRoot;
                    height -= 1;
                }
                db.pool.unfix(pg);
            }
            updateCounter += 1;
            Modify();
            return(true);
        }