Esempio n. 1
0
        public void Compatibility()
        {
            var original = BitVector.Of(0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00);

            fixed(ulong *storage = original.Bits)
            {
                var ptr = new PtrBitVector((byte *)storage, 64);

                for (int i = 0; i < 64; i++)
                {
                    Assert.Equal(original[i], ptr[i]);
                }
            };
        }
Esempio n. 2
0
        private unsafe void UnsetValue(FixedSizeTree fst, long pageNumber, int positionInBitmap)
        {
            bool  isNew;
            byte *ptr;

            using (fst.DirectAdd(pageNumber, out isNew, out ptr))
            {
                if (isNew)
                {
                    ThrowInvalidNewBuffer();
                }

                PtrBitVector.SetBitInPointer(ptr, positionInBitmap, false);
                // ptr[positionInBitmap / 8] &= (byte) ~(1 << (positionInBitmap % 8));
            }
        }
Esempio n. 3
0
        public unsafe Report GetNumberOfPreAllocatedFreePages()
        {
            var fst = _parentTree.FixedTreeFor(AllocationStorage, valSize: BitmapSize);

            if (fst.NumberOfEntries == 0)
            {
                return(new Report());
            }

            var free = 0;

            using (var it = fst.Iterate())
            {
                if (it.Seek(long.MinValue) == false)
                {
                    throw new InvalidOperationException($"Could not seek to the first element of {fst.Name} tree");
                }

                Slice slice;
                using (it.Value(out slice))
                {
                    byte *ptr = slice.Content.Ptr;
                    for (int i = 0; i < NumberOfPagesInSection; i++)
                    {
                        if (PtrBitVector.GetBitInPointer(ptr, i) == false)
                        {
                            free++;
                        }
                    }
                }
            }

            int amountOfPagesActuallyAllocated = GetNumberOfPagesToAllocate();

            return(new Report
            {
                NumberOfOriginallyAllocatedPages = fst.NumberOfEntries * amountOfPagesActuallyAllocated,
                NumberOfFreePages = free
            });
        }
Esempio n. 4
0
        public void SetIndex()
        {
            var original = new byte[8] {
                0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00
            };

            fixed(byte *storage = original)
            {
                var ptr = new PtrBitVector(storage, 64);
                int idx = ptr.FindLeadingOne();

                Assert.Equal(false, ptr[idx - 1]);
                Assert.Equal(true, ptr[idx]);
                Assert.Equal(false, ptr[idx + 1]);

                ptr.Set(idx, false);
                ptr.Set(idx + 1, true);

                Assert.Equal(false, ptr[idx - 1]);
                Assert.Equal(false, ptr[idx]);
                Assert.Equal(true, ptr[idx + 1]);
            };
        }
Esempio n. 5
0
        public unsafe Page AllocateSinglePage(long nearbyPage)
        {
            var fst = _parentTree.FixedTreeFor(AllocationStorage, valSize: BitmapSize);

            using (var it = fst.Iterate())
            {
                Page page;
                if (it.Seek(nearbyPage)) // found a value >= from the nearby page
                {
                    if (it.CurrentKey > nearbyPage)
                    {
                        // go back one step if we can
                        if (it.MovePrev() == false)
                        {
                            it.Seek(nearbyPage); // if we can't, go back to the original find
                        }
                    }
                }
                else // probably it is on the last entry, after the first page, so we'll use the last entry
                {
                    if (it.SeekToLast() == false)
                    {
                        // shouldn't actuallly happen, but same behavior as running out of space
                        page = AllocateMoreSpace(fst);
                        SetValue(fst, page.PageNumber, 0);
                        return(page);
                    }
                }
                var startPage = it.CurrentKey;
                while (true)
                {
                    Slice slice;
                    using (it.Value(out slice))
                    {
                        var hasSpace = false;
                        var buffer   = (ulong *)(slice.Content.Ptr);
                        for (int i = 0; i < BitmapSize / sizeof(ulong); i++)
                        {
                            if (buffer[i] != ulong.MaxValue)
                            {
                                hasSpace = true;
                                break;
                            }
                        }
                        if (hasSpace == false)
                        {
                            if (TryMoveNextCyclic(it, startPage) == false)
                            {
                                break;
                            }
                        }
                        for (int i = 0; i < BitmapSize * 8; i++)
                        {
                            if (PtrBitVector.GetBitInPointer(buffer, i) == false)
                            {
                                var currentSectionStart = it.CurrentKey;
                                SetValue(fst, currentSectionStart, i);

                                return(_llt.ModifyPage(currentSectionStart + i));
                            }
                        }
                        if (TryMoveNextCyclic(it, startPage) == false)
                        {
                            break;
                        }
                    }
                }
                page = AllocateMoreSpace(fst);
                SetValue(fst, page.PageNumber, 0);
                return(page);
            }
        }