public PersistentIndex(PersistentIndexName name)
        {
            var folder = name.Folder;

            if (!PersistentIndexInfo.Exists(folder, FileNameInfo))
            {
                throw new InvalidOperationException("No index");
            }

            HeaderReader = new PersistentIndexInfo(folder, FileNameInfo);
            Header       = HeaderReader.Read();
            if (Header == null)
            {
                throw new InvalidOperationException("No index");
            }

            VerifyHeader(name);
            var indexType = Header.Type.Split(' ');

            Dictionary      = PersistentDictionaryFactory.Create(indexType[1], folder, FileNameDictionary, Header.MaxTokenSize, indexType[4]);
            PostingLists    = PostingListIOFactory.CreateReader(indexType[3], folder, FileNamePostingLists);
            PosIndex        = PersistentDictionaryFactory.Create(indexType[1], folder, FileNamePosIndex, PosIndexKeySize, indexType[4]);
            PositionsReader = new DeltaVarIntListReader(folder, FileNamePositions);
            Fields          = PersistentMetadataFactory.CreateStorage(indexType[2], folder, FileNameFields);
            this.name       = name;
        }
Beispiel #2
0
        public static void Test()
        {
            int  N         = 1000000;
            int  variation = 10000000;
            long listStart = -1;

            var timer = Stopwatch.StartNew();
            var ar    = new ulong[N];

            using (var mem = new MemoryStorage())
            {
                using (var writer = new DeltaVarIntListWriter(mem.GetReference()))
                {
                    var s1   = writer.StartList();
                    var prev = 0UL;
                    var r    = new Random(2019);
                    for (int i = 0; i < N; ++i)
                    {
                        prev += 1 + (ulong)r.Next(variation);
                        ar[i] = prev;
                        writer.AddValue(prev);
                    }
                    var e1 = writer.EndList();
                    Console.WriteLine($"Count  : {N}");
                    Console.WriteLine($"Length : {e1 - s1}");

                    listStart = s1;
                }
                Console.WriteLine($"Write  : {timer.Elapsed}");

                timer = Stopwatch.StartNew();
                using (var reader = new DeltaVarIntListReader(mem.GetReference()))
                {
                    int i = 0;
                    foreach (var v in reader.Get(listStart))
                    {
                        if (ar[i] != v)
                        {
                            throw new Exception($"{ar[i]} != {v} at {i}");
                        }
                        ++i;
                    }
                }
                Console.WriteLine($"Read   : {timer.Elapsed}");

                timer = Stopwatch.StartNew();
                using (var reader = new DeltaVarIntListReader(mem.GetReference()))
                {
                    for (int i = 0; i < N; ++i)
                    {
                        var v = reader.GetLowerBound(listStart, ar[i]).First();
                        if (ar[i] != v)
                        {
                            throw new Exception($"{ar[i]} != {v} at {i}");
                        }
                    }
                }
                Console.WriteLine($"Seek   : {timer.Elapsed}");
            }
        }