Ejemplo n.º 1
0
 public Enumerator(BitMap map)
 {
     _index = -1;
     _mask  = 0;
     _bit   = 0;
     _map   = map;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntryTable{TValue}"/> class with the specified capacity.
        /// </summary>
        /// <param name="capacity">Capacity of the table</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity"/> is less than 0</exception>
        public EntryTable(int capacity)
        {
            if (capacity < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(capacity));
            }

            _freeHint  = 0;
            _allocated = new BitMap();
            _table     = GC.AllocateArray <TEntry>(capacity, pinned: true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntryTable{TEntry}"/> class with the desired page size in
        /// bytes.
        /// </summary>
        /// <param name="pageSize">Desired page size in bytes</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="pageSize"/> is less than 0</exception>
        /// <exception cref="ArgumentException"><typeparamref name="TEntry"/>'s size is zero</exception>
        /// <remarks>
        /// The actual page size may be smaller or larger depending on the size of <typeparamref name="TEntry"/>.
        /// </remarks>
        public unsafe EntryTable(int pageSize = 4096)
        {
            if (pageSize < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(pageSize), "Page size cannot be negative.");
            }

            if (sizeof(TEntry) == 0)
            {
                throw new ArgumentException("Size of TEntry cannot be zero.");
            }

            _allocated       = new BitMap(NativeAllocator.Instance);
            _pages           = new Dictionary <int, IntPtr>();
            _pageLogCapacity = BitOperations.Log2((uint)(pageSize / sizeof(TEntry)));
            _pageCapacity    = 1 << _pageLogCapacity;
        }
Ejemplo n.º 4
0
        public bool Clear(BitMap map)
        {
            EnsureCapacity(map._masks.Count * IntSize);

            bool modified = false;

            for (int index = 0; index < _masks.Count; index++)
            {
                int newValue = _masks[index] & ~map._masks[index];

                if (_masks[index] != newValue)
                {
                    _masks[index] = newValue;

                    modified = true;
                }
            }

            return(modified);
        }
Ejemplo n.º 5
0
        public bool Set(BitMap map)
        {
            EnsureCapacity(map._count * IntSize);

            bool modified = false;

            for (int index = 0; index < _count; index++)
            {
                long newValue = _masks[index] | map._masks[index];

                if (_masks[index] != newValue)
                {
                    _masks[index] = newValue;

                    modified = true;
                }
            }

            return(modified);
        }
Ejemplo n.º 6
0
 public static BitMap Allocate(int initialCapacity)
 {
     BitMap result = ThreadStaticPool<BitMap>.Instance.Allocate();
     result.Reset(initialCapacity);
     return result;
 }