コード例 #1
0
ファイル: InMemoryStore.cs プロジェクト: meikeric/deveeldb
        private InMemoryBlock GetAreaBlock(long pointer)
        {
            lock (this) {
                // Find the pointer in the hash
                var           hashPos = (int)(pointer % areaMap.Length);
                InMemoryBlock prev    = null;
                var           block   = areaMap[hashPos];

                // Search for this pointer
                while (block != null && block.Id != pointer)
                {
                    prev  = block;
                    block = block.Next;
                }

                if (block == null)
                {
                    throw new IOException("Pointer " + pointer + " is invalid.");
                }

                // Move the element to the start of the list.
                if (prev != null)
                {
                    prev.Next        = block.Next;
                    block.Next       = areaMap[hashPos];
                    areaMap[hashPos] = block;
                }

                return(block);
            }
        }
コード例 #2
0
ファイル: InMemoryStore.cs プロジェクト: meikeric/deveeldb
        /// <inheritdoc/>
        public void DeleteArea(long id)
        {
            lock (this) {
                // Find the pointer in the hash
                var           hashPos = (int)(id % areaMap.Length);
                InMemoryBlock prev    = null;
                InMemoryBlock block   = areaMap[hashPos];

                // Search for this pointer
                while (block != null && block.Id != id)
                {
                    prev  = block;
                    block = block.Next;
                }

                // If not found
                if (block == null)
                {
                    throw new IOException("Area ID " + id + " is invalid.");
                }

                // Remove
                if (prev == null)
                {
                    areaMap[hashPos] = block.Next;
                }
                else
                {
                    prev.Next = block.Next;
                }

                // Garbage collector should do the rest...
            }
        }
コード例 #3
0
ファイル: InMemoryStore.cs プロジェクト: meikeric/deveeldb
        /// <inheritdoc/>
        public IArea CreateArea(long size)
        {
            if (size > Int32.MaxValue)
            {
                throw new IOException("'size' is too large.");
            }

            lock (this) {
                // Generate a unique id for this area.
                long id = uniqueIdKey;
                ++uniqueIdKey;

                // Create the element.
                var element = new InMemoryBlock(id, (int)size);

                // The position in the hash map
                int hashPos = (int)(id % areaMap.Length);

                // Add to the chain
                element.Next     = areaMap[hashPos];
                areaMap[hashPos] = element;

                return(element.GetArea(false));
            }
        }
コード例 #4
0
ファイル: InMemoryStore.cs プロジェクト: meikeric/deveeldb
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         fixedAreaBlock = null;
         areaMap        = null;
     }
 }
コード例 #5
0
        private void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (areaMap != null)
                {
                    for (int i = 0; i < areaMap.Length; i++)
                    {
                        var block = areaMap[i];
                        if (block != null)
                        {
                            block.Dispose();
                        }

                        areaMap[i] = null;
                    }
                }
            }

            fixedAreaBlock = null;
            areaMap        = null;
        }
コード例 #6
0
ファイル: InMemoryStore.cs プロジェクト: deveel/deveeldb
        /// <inheritdoc/>
        public IArea CreateArea(long size)
        {
            if (size > Int32.MaxValue)
                throw new IOException("'size' is too large.");

            lock (this) {
                // Generate a unique id for this area.
                long id = uniqueIdKey;
                ++uniqueIdKey;

                // Create the element.
                var element = new InMemoryBlock(id, (int)size);

                // The position in the hash map
                int hashPos = (int)(id % areaMap.Length);

                // Add to the chain
                element.Next = areaMap[hashPos];
                areaMap[hashPos] = element;

                return element.GetArea(false);
            }
        }
コード例 #7
0
ファイル: InMemoryStore.cs プロジェクト: deveel/deveeldb
        private void Dispose(bool disposing)
        {
            if (disposing) {
                if (areaMap != null) {
                    for (int i = 0; i < areaMap.Length; i++) {
                        var block = areaMap[i];
                        if (block != null)
                            block.Dispose();

                        areaMap[i] = null;
                    }
                }
            }

            fixedAreaBlock = null;
            areaMap = null;
        }
コード例 #8
0
ファイル: InMemoryStore.cs プロジェクト: furesoft/deveeldb
 private void Dispose(bool disposing)
 {
     if (disposing) {
         fixedAreaBlock = null;
         areaMap = null;
     }
 }