コード例 #1
0
        public bool Remove(byte[] key)
        {
            _rootNode.TotalSpaceAvailable = _rootNode.CalcSize() + _file.MftRecordFreeSpace(AttributeType.IndexRoot, _name);

            IndexEntry overflowEntry;
            bool       found = _rootNode.RemoveEntry(key, out overflowEntry);

            if (overflowEntry != null)
            {
                throw new IOException("Error removing entry, root overflowed");
            }

            return(found);
        }
コード例 #2
0
ファイル: IndexNode.cs プロジェクト: ibeae/ThinkAway.net
        public bool RemoveEntry(byte[] key, out IndexEntry newParentEntry)
        {
            bool       exactMatch;
            int        entryIndex = GetEntry(key, out exactMatch);
            IndexEntry entry      = _entries[entryIndex];

            if (exactMatch)
            {
                if ((entry.Flags & IndexEntryFlags.Node) != 0)
                {
                    IndexNode  childNode = _index.GetSubBlock(entry).Node;
                    IndexEntry rLeaf     = childNode.FindLargestLeaf();

                    byte[] newKey  = rLeaf.KeyBuffer;
                    byte[] newData = rLeaf.DataBuffer;

                    IndexEntry newEntry;
                    childNode.RemoveEntry(newKey, out newEntry);
                    entry.KeyBuffer  = newKey;
                    entry.DataBuffer = newData;

                    if (newEntry != null)
                    {
                        InsertEntryThisNode(newEntry);
                    }

                    newEntry = LiftNode(entryIndex);
                    if (newEntry != null)
                    {
                        InsertEntryThisNode(newEntry);
                    }

                    newEntry = PopulateEnd();
                    if (newEntry != null)
                    {
                        InsertEntryThisNode(newEntry);
                    }

                    // New entry could be larger than old, so may need
                    // to divide this node...
                    newParentEntry = EnsureNodeSize();
                }
                else
                {
                    _entries.RemoveAt(entryIndex);
                    newParentEntry = null;
                }

                _store();
                return(true);
            }
            else if ((entry.Flags & IndexEntryFlags.Node) != 0)
            {
                IndexNode  childNode = _index.GetSubBlock(entry).Node;
                IndexEntry newEntry;
                if (childNode.RemoveEntry(key, out newEntry))
                {
                    if (newEntry != null)
                    {
                        InsertEntryThisNode(newEntry);
                    }

                    newEntry = LiftNode(entryIndex);
                    if (newEntry != null)
                    {
                        InsertEntryThisNode(newEntry);
                    }

                    newEntry = PopulateEnd();
                    if (newEntry != null)
                    {
                        InsertEntryThisNode(newEntry);
                    }

                    // New entry could be larger than old, so may need
                    // to divide this node...
                    newParentEntry = EnsureNodeSize();

                    _store();
                    return(true);
                }
            }

            newParentEntry = null;
            return(false);
        }