Пример #1
0
        private static int BinarySearch(TreeEntry[] entries, byte[] nameUTF8, int nameUTF8last
                                        , int nameStart, int nameEnd)
        {
            if (entries.Length == 0)
            {
                return(-1);
            }
            int high = entries.Length;
            int low  = 0;

            do
            {
                int mid = (int)(((uint)(low + high)) >> 1);
                int cmp = CompareNames(entries[mid].GetNameUTF8(), nameUTF8, nameStart, nameEnd,
                                       TreeEntry.LastChar(entries[mid]), nameUTF8last);
                if (cmp < 0)
                {
                    low = mid + 1;
                }
                else
                {
                    if (cmp == 0)
                    {
                        return(mid);
                    }
                    else
                    {
                        high = mid;
                    }
                }
            }while (low < high);
            return(-(low + 1));
        }
Пример #2
0
        /// <summary>Add the specified tree entry to this tree.</summary>
        /// <remarks>Add the specified tree entry to this tree.</remarks>
        /// <param name="e"></param>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public virtual void AddEntry(TreeEntry e)
        {
            int p;

            EnsureLoaded();
            p = BinarySearch(contents, e.GetNameUTF8(), TreeEntry.LastChar(e), 0, e.GetNameUTF8
                                 ().Length);
            if (p < 0)
            {
                e.AttachParent(this);
                InsertEntry(p, e);
            }
            else
            {
                throw new EntryExistsException(e.GetName());
            }
        }
Пример #3
0
        internal virtual void RemoveEntry(TreeEntry e)
        {
            TreeEntry[] c = contents;
            int         p = BinarySearch(c, e.GetNameUTF8(), TreeEntry.LastChar(e), 0, e.GetNameUTF8(
                                             ).Length);

            if (p >= 0)
            {
                TreeEntry[] n = new TreeEntry[c.Length - 1];
                for (int k = c.Length - 1; k > p; k--)
                {
                    n[k - 1] = c[k];
                }
                for (int k_1 = p - 1; k_1 >= 0; k_1--)
                {
                    n[k_1] = c[k_1];
                }
                contents = n;
                SetModified();
            }
        }