コード例 #1
0
ファイル: BPlusTree.cs プロジェクト: zigaosolin/SharpMedia
        /// <summary>
        /// Inserts a new entry into B+ tree, increasing count of all sequent indices.
        /// </summary>
        /// <param name="services">The services.</param>
        /// <param name="index">Index where to insert.</param>
        /// <param name="info">The info of object.</param>
        public void Insert(Journalling.IService services,
                           bool before, ObjectInfo info)
        {
            Block             block   = services.Read(BlockType.BPlusTreeBlock, rootAddress);
            List <ObjectInfo> objects = ExtractObjectsFromLeaf(block);

            // We convert all to before.
            if (!before)
                info.Index--; }
コード例 #2
0
ファイル: BPlusTree.cs プロジェクト: zigaosolin/SharpMedia
        /// <summary>
        /// Adds a new entry into B+ tree. If it already exists, exception is thrown.
        /// </summary>
        /// <param name="services">The services node.</param>
        /// <param name="info"></param>
        public unsafe void Add(Journalling.IService services, ObjectInfo info)
        {
            Block             block   = services.Read(BlockType.BPlusTreeBlock, rootAddress);
            List <ObjectInfo> objects = ExtractObjectsFromLeaf(block);

            // We check if already exists (may remove this in fitire for performance reasons).
            if (objects.Exists(delegate(ObjectInfo other) { return(other.Index == info.Index); }))
            {
                throw new DatabaseException("Adding to existing location.");
            }

            // We add the new object and write.
            InsertToOrderedCollection(objects, info);
            if (!WriteObjectsToLeaf(block, MaxObjectFit(services.BlockSize), objects))
            {
                throw new NotSupportedException();
            }

            services.Write(BlockType.BPlusTreeBlock, rootAddress, block);
        }