Exemple #1
0
        public void LoadEntries()
        {
            SpanReader sr = new SpanReader(_buffer, Endian.Big);

            sr.Position = (int)_offsetStart;

            uint offsetAndCount = sr.ReadUInt32();
            uint nodeCount      = sr.ReadUInt16();

            for (int i = 0; i < nodeCount; i++)
            {
                uint keyCount   = GetBitsAt(ref sr, 0) & 0x7FFu;
                uint nextOffset = GetBitsAt(ref sr, keyCount + 1);

                for (uint j = 0; j < keyCount; j++)
                {
                    uint offset = GetBitsAt(ref sr, j + 1);
                    var  data   = sr.GetReaderAtOffset((int)offset);

                    TKey key = new TKey();
                    key.Deserialize(ref data);
                    Entries.Add(key);
                }

                sr.Position += (int)nextOffset;
            }
        }
Exemple #2
0
        public void TraverseAndUnpack(EntryUnpacker unpacker)
        {
            SpanReader sr = new SpanReader(_buffer, Endian.Big);

            sr.Position += _offsetStart;

            uint offsetAndCount = sr.ReadUInt32();

            uint nodeCount = sr.ReadUInt16();

            for (int i = 0; i < nodeCount; i++)
            {
                uint high       = CryptoUtils.GetBitsAt(ref sr, 0) & 0x7FFu;
                uint nextOffset = CryptoUtils.GetBitsAt(ref sr, high + 1);

                for (uint j = 0; j < high; j++) // high is pretty much entry count
                {
                    uint offset = CryptoUtils.GetBitsAt(ref sr, j + 1);
                    var  data   = sr.GetReaderAtOffset((int)offset);

                    FileEntryKey key = new FileEntryKey();
                    key.OffsetFromTree = data.Position;

                    key.Deserialize(ref data);
                    unpacker.UnpackFromKey(key);
                }

                sr.Position += (int)nextOffset;
            }
        }
Exemple #3
0
        public SpanReader SearchWithComparison(ref SpanReader sr, uint count, TKey key, SearchResult res, SearchCompareMethod method)
        {
            uint high  = GetBitsAt(ref sr, 0) & 0x7FFu;
            uint low   = 0;
            uint index = 0;

            res.upperBound = high;

            SpanReader subData = default;

            while (low < high)
            {
                uint mid = low + (high - low) / 2;
                index = mid + 1;
                uint offset = GetBitsAt(ref sr, index);

                subData = sr.GetReaderAtOffset((int)offset);

                int ret;
                if (method == SearchCompareMethod.LessThan)
                {
                    ret = LessThanKeyCompareOp(key, ref subData);
                }
                else if (method == SearchCompareMethod.EqualTo)
                {
                    ret = EqualToKeyCompareOp(key, ref subData);
                }
                else
                {
                    throw new ArgumentException($"Invalid search method provided '{method}'");
                }

                if (ret == 0)
                {
                    res.lowerBound = mid;
                    res.index      = mid;
                    return(subData);
                }
                else if (ret > 0)
                {
                    low = index;
                }
                else if (ret < 0)
                {
                    high  = mid;
                    index = mid;
                }
            }

            subData.Position = -1;

            res.lowerBound = index;
            res.index      = ~0u;

            if (count != 0 && index != res.upperBound)
            {
                uint offset = GetBitsAt(ref sr, index + 1);
                subData = sr.GetReaderAtOffset((int)offset);
            }

            return(subData);
        }