示例#1
0
        /// <summary>
        /// Tries to find an item on the table.
        /// </summary>
        /// <param name="dataAccessor">Data accessor</param>
        /// <param name="item">Item, if found</param>
        /// <param name="data">Data, if found</param>
        /// <returns>True if the item was found on the table, false otherwise</returns>
        public bool TryFindItem(IDataAccessor dataAccessor, out T item, out byte[] data)
        {
            SmartDataAccessor sda = new SmartDataAccessor(dataAccessor);

            item = default;
            data = null;

            int left  = 0;
            int right = _sizeTable.Count;

            while (left != right)
            {
                int index = left + ((right - left) >> 1);

                PartitionHashTable <T> .SearchResult result = _sizeTable[index].TryFindItem(ref sda, ref item, ref data);

                if (result == PartitionHashTable <T> .SearchResult.FoundFull)
                {
                    return(true);
                }

                if (result == PartitionHashTable <T> .SearchResult.NotFound)
                {
                    right = index;
                }
                else /* if (result == PartitionHashTable<T>.SearchResult.FoundPartial) */
                {
                    left = index + 1;
                }
            }

            data = null;
            return(false);
        }
示例#2
0
 /// <summary>
 /// Creates an entry for a given size.
 /// </summary>
 /// <param name="size">Size of the data to be stored on this entry</param>
 public SizeEntry(int size)
 {
     Size   = size;
     _table = new PartitionHashTable <T>();
 }