public void Load() // В стандартном случае, задается null { offsetsCell.Clear(); if (!offsetsOnOffsetsCell.IsEmpty && offsetsOnOffsetsCell.Root.Count() != (long)Int32.MaxValue + Int32.MaxValue) { offsetsOnOffsetsCell.Clear(); } if (offsetsOnOffsetsCell.IsEmpty) { offsetsOnOffsetsCell.Fill(new object[0]); for (int i = Int32.MinValue; i < Int32.MaxValue; i++) { offsetsOnOffsetsCell.Root.AppendElement(long.MinValue); } offsetsOnOffsetsCell.Flush(); } else { for (long i = 0; i < (long)Int32.MaxValue + Int32.MaxValue; i++) { offsetsOnOffsetsCell.Root.Element(i).Set(long.MinValue); } } offsetsCell.Fill(new object[0]); ArrayIntMax <bool> hashExists = new ArrayIntMax <bool>(); foreach (var rec in table.Root.Elements()) //.Where(ent => (bool)ent.Field(0).Get() == false) загрузка всех элементов за исключением уничтоженных { Tkey key = keyProducer(rec); Int32 hash = hashProducer(key); var offsetOnOffsetEntry = offsetsOnOffsetsCell.Root.Element((long)hash + (long)Int32.MaxValue); if (hashExists[hash]) { entryOffsetCell.offset = (long)offsetOnOffsetEntry.Get() + 8; //пропускаем первый. int i = 1; while ((long)entryOffsetCell.Get() != long.MinValue) { if (++i == CollisionMax) { throw new Exception( "Достигнуо максимально допустимое количество ключей с одинаковым хэш-значением"); } entryOffsetCell.offset += 8; } entryOffsetCell.Set(rec.offset); } else { hashExists[hash] = true; offsetOnOffsetEntry.Set(offsetsCell.Root.AppendElement(rec.offset)); for (int i = 1; i < CollisionMax; i++) { offsetsCell.Root.AppendElement(long.MinValue); } } } offsetsCell.Flush(); }
public int GetCode(string name) { Open(true); if (Count == 0) { return(Int32.MinValue); } long newMd5 = BitConverter.ToInt64(md5.ComputeHash(Encoding.UTF8.GetBytes(name)), 0); if (Count == 0) { return(Int32.MinValue); } PaEntry ncEntry = nc_cell.Root.Element(0); List <long> offsets; object[] code_name; if (collisionsByMD5.TryGetValue(newMd5, out offsets)) { foreach (long offset in offsets) { ncEntry.offset = offset; code_name = (object[])ncEntry.Get(); if ((string)code_name[1] == name) { return((int)code_name[0]); } } return(int.MinValue); } long offsetUni; if (!offsetByMd5.TryGetValue(newMd5, out offsetUni)) { return(Int32.MinValue); } ncEntry.offset = offsetUni; code_name = (object[])ncEntry.Get(); return((string)code_name[1] == name ? (int)code_name[0] : Int32.MinValue); //for (;;index++) //{ // var md5_offet=(object[])md5_index.Root.Element(index).Get(); // if ((long)md5_offet[0] != newD5) return Int32.MinValue; // ncEntry.offset = (long) md5_offet[1]; // if ((string)ncEntry.Field(1).Get() == name) // return (int)ncEntry.Field(0).Get(); //} //return Int32.MinValue; }
protected override void AddInIndex(PaEntry entry) { int node; if (entry.Type.Vid == PTypeEnumeration.integer) { node = (int)entry.Get(); if (!searchIndex.ContainsKey(node)) { searchIndex.Add(node, entry.offset); } } else { node = (int)entry.Field(0).Get(); if (!searchIndex.ContainsKey(node)) { searchIndex.Add(node, entry.offset); } foreach (var chiledEntry in entry.Field(1).Elements()) { AddInIndex(chiledEntry); } } }
public IEnumerable <PaEntry> GetAllByKey(long start, long number, Tkey key) { if (Table == null || Table.Count() == 0) { return(Enumerable.Empty <PaEntry>()); } PaEntry entry = Table.Element(0); PaEntry entry1 = entry; int hkey = HalfProducer(key); var qqq = index_cell.Root.Elements().Take(100).ToArray(); var candidates = index_cell.Root.BinarySearchAll(start, number, ent => { object[] pair = (object[])ent.Get(); int hk = (int)pair[0]; int cmp = hk.CompareTo(hkey); if (cmp != 0) { return(cmp); } long off = (long)pair[1]; entry.offset = off; return(((IComparable)KeyProducer((object[])entry.Get())).CompareTo(key)); }).ToArray(); return(candidates.Select(ent => { entry1.offset = (long)ent.Field(1).Get(); return entry1; })); }
// Доступ к литералу по коду: читается все структурные значение литерала internal object GetLiteralPValue(long ocode) { PaEntry entry = literals.Root.Element(0); entry.offset = ocode; return(entry.Get()); }
/// <summary> /// Получение триплетов из диапазона, соответствующих заданному второму ключу /// </summary> /// <param name="dia">Диапазон в индексном массиве. Есть специальные требования к диапазону</param> /// <param name="key2">Ключ2 по которому фильтруется результарующее множество</param> /// <returns>Возвращает поток триплетов в объектной форме</returns> public IEnumerable <object> GetAllInDiap(Diapason dia, Tkey key2) { if (dia.IsEmpty()) { return(Enumerable.Empty <object>()); } int hkey = Half2Producer(key2); PaEntry entry = Table.Element(0); var query1 = index_cell.Root.BinarySearchAll(dia.start, dia.numb, ent => { object[] va = (object[])ent.Get(); int hk = (int)va[2]; int cmp = hk.CompareTo(hkey); return(cmp); }).Select(ent => ent.Get()) .Where(va => (int)((object[])va)[2] == hkey); var query2 = index_cell.Root.ElementValues(dia.start, dia.numb) .Where(va => (int)((object[])va)[2] == hkey); IEnumerable <object> query = dia.numb > 30 ? query1 : query2; return(query .Select(va => { long off = (long)((object[])va)[0]; entry.offset = off; return entry.Get(); }) .Where(two => !(bool)((object[])two)[0] && Key2Producer(two).CompareTo(key2) == 0) .Select(two => ((object[])((object[])two)[1]))); }
public IEnumerable <PaEntry> GetAllByLevel(Func <Tkey, int> LevelFunc) { //throw new Exception("GetAllByLevel dois not implemented in DinamicIndexUnique"); PaEntry[] dyna = new PaEntry[0]; if (_unique) { dyna = keyent.Where(pair => LevelFunc(pair.Key) == 0).Select(pair => pair.Value).ToArray(); } else { dyna = keyents.Where(pair => LevelFunc(pair.Key) == 0).SelectMany(pair => pair.Value).ToArray(); } if (Table.Count() == 0) { return(dyna); } PaEntry ent = Table.Element(0); return(dyna.Concat(IndexArray.IndexCell.Root.BinarySearchAll(e => { long off = (long)e.Get(); ent.offset = off; Tkey k = KeyProducer(ent.Get()); return LevelFunc(k); }))); }
// =============== Частные случаи ================= public PValue GetById(string id) { if (table.Count() == 0) { return(new PValue(null, Int64.MinValue, null)); } PaEntry entry = table.Element(0); PaEntry index_entry = index_cell.Root.BinarySearchFirst(ent => { long off = (long)ent.Get(); entry.offset = off; return(0 - id.CompareTo((string)entry.Field(i_field).Get())); }); if (index_entry.offset == Int64.MinValue) { return(new PValue(null, Int64.MinValue, null)); } long cell_offset = (long)index_entry.Get(); entry.offset = cell_offset; var rec = entry.GetValue(); return(rec); }
public IEnumerable <object> GetPersonsByName(string firstpartofname) { firstpartofname = firstpartofname.ToLower(); PaEntry entry = tab_person.Element(0); var query = index_person_name.GetAllByLevel(s => { string ss = s.ToLower(); if (ss.StartsWith(firstpartofname)) { return(0); } return(ss.CompareTo(firstpartofname)); }); return(query .Select(ent => { //long off = (long)ent.Get(); //entry.offset = off; return entry.Get(); }) .Cast <object[]>() .Where(pair => !((bool)pair[0])) .Select(pair => pair[1])); }
public XElement GetItemByIdBasic(string id, bool addinverse) { PaEntry ent = id_index.GetFirst(id); object[] item = (object[])ent.Get(); XElement res = new XElement("record", new XAttribute("id", item[1]), new XAttribute("type", item[2]), ((object[])item[3]).Cast <object[]>().Select(v3 => new XElement("field", new XAttribute("prop", v3[0]), string.IsNullOrEmpty((string)v3[2])?null: new XAttribute(ONames.xmllang, v3[2]), v3[1])), ((object[])item[4]).Cast <object[]>().Select(v2 => new XElement("direct", new XAttribute("prop", v2[0]), v2[1])), null); if (addinverse) { var qu = inverse_index.GetAll(id).Select(en => en.Get()).Cast <object[]>() .SelectMany(v5 => ((object[])v5[4]).Where(v2 => (string)((object[])v2)[1] == id).Select(v2 => new XElement("inverse", new XAttribute("prop", ((object[])v2)[0]), new XElement("record", new XAttribute("id", v5[1]))))); res.Add(qu); } return(res); }
internal Literal DecodeDataCode(long lcode) { PaEntry lit_ent = literals.Root.Element(0); lit_ent.offset = lcode; return(new Literal((object[])lit_ent.Get())); }
public static void Main1(string[] args) { System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); PType tp_rec = new PTypeRecord( new NamedType("id", new PType(PTypeEnumeration.integer)), new NamedType("name", new PType(PTypeEnumeration.sstring)), new NamedType("age", new PType(PTypeEnumeration.integer))); PaCell cell = new PaCell(new PTypeSequence(tp_rec), path + "people.pac", false); PType tp_pair = new PTypeRecord( new NamedType("id", new PType(PTypeEnumeration.integer)), new NamedType("offset", new PType(PTypeEnumeration.longinteger))); PaCell cell_index = new PaCell(new PTypeSequence(tp_pair), path + "people_index.pac", false); int npersons = 1_000_000; Random rnd = new Random(); Console.WriteLine("Start Task04: Main1"); // Загрузка данных sw.Restart(); cell.Clear(); cell.Fill(new object[0]); cell_index.Clear(); cell_index.Fill(new object[0]); for (int i = 0; i < npersons; i++) { int code = npersons - i; long offset = cell.Root.AppendElement(new object[] { code, "=" + code + "=", rnd.Next(120) }); cell_index.Root.AppendElement(new object[] { code, offset }); } cell.Flush(); cell_index.Flush(); cell_index.Root.SortByKey <int>(pair => (int)((object[])pair)[0]); sw.Stop(); Console.WriteLine($"load {npersons} records. duration {sw.ElapsedMilliseconds}"); // Поиск int key = npersons * 2 / 3; int ntests = 10000; sw.Restart(); PaEntry entry = cell.Root.Element(0); for (int j = 0; j < ntests; j++) { key = rnd.Next(npersons); PaEntry en = cell_index.Root.BinarySearchFirst(ent => ((int)((object[])ent.Get())[0]).CompareTo(key)); object operson = entry.SetOffset((long)((object[])en.Get())[1]).Get(); //Console.WriteLine($"val={tp_rec.Interpret(operson)}"); } sw.Stop(); Console.WriteLine($"getByKey {ntests} times. duration {sw.ElapsedMilliseconds}"); }
public XElement GetItemById(string id, XElement format) { PaEntry ent = id_index.GetFirst(id); if (ent.offset == Int64.MinValue) { return(null); } object[] valu = (object[])ent.Get(); XElement record = GetItemF5(valu, format); return(record); }
public void Build() { index_cell.Clear(); index_cell.Fill(new object[0]); if (Key1Producer == null) { throw new Exception("Err: Key1Producer not defined"); } if (Key2Producer == null) { throw new Exception("Err: Key2Producer not defined"); } Table.Scan((offset, o) => { var k1 = Key1Producer(o); var k2 = Key2Producer(o); int hk2 = Half2Producer(k2); index_cell.Root.AppendElement(new object[] { offset, k1, hk2 }); return(true); }); index_cell.Flush(); PaEntry entry = Table.Element(0); index_cell.Root.SortByKey <GroupElement>(ob => new GroupElement((int)((object[])ob)[1], (int)((object[])ob)[2], () => { long off = (long)((object[])ob)[0]; entry.offset = off; return(Key2Producer(entry.Get())); })); // BuildGroupsIndexSpecial: groups_index.Clear(); groups_index.Fill(new object[0]); int key1 = Int32.MinValue; int i = 0; // Теоретически, здесь есть проблема в том, что элементы могут выдаватьс не по индексу. foreach (object[] va in index_cell.Root.ElementValues()) { int k1 = (int)va[1]; if (k1 > key1) { groups_index.Root.AppendElement(i); key1 = k1; } i++; } groups_index.Flush(); //CreateGroupDictionary(); CreateDiscaleDictionary(); }
// Сортировка по дополнительному индексу. Предполагается, что по первичному индексу сортировка уже произведена public void AdditionalIndex(int second_field) { long start = 0; object current_prime_value = null; if (table.Count() == 0) { return; } PaEntry tab_entry = table.Element(0); // Нулевой элемент таблицы PType second_type = tab_entry.Field(second_field).Type; long llen = index_cell.Root.Count(); if (llen == 0) { return; } PaEntry ent = index_cell.Root.Element(0); PType tel = ent.Type; int size = tel.HeadSize; long offset = ent.offset; for (long ii = 0; ii < llen; ii++) { ent.offset = offset; offset += size; long tab_offset = (long)ent.Get(); tab_entry.offset = tab_offset; object prime_value = tab_entry.Field(i_field).Get(); int cmp; if (current_prime_value == null) { current_prime_value = prime_value; start = ii; } else if ((cmp = ((IComparable)prime_value).CompareTo(current_prime_value)) != 0 || ii == llen - 1) // Смена значения первичного ключа { long number = ii - start + (cmp == 0 && ii == llen - 1? 1 : 0); if (number > 1) { // нужно сделать сортировку по вторичному ключу index_cell.Root.SortByKey <string>(start, number, (object v) => { tab_entry.offset = (long)v; return((string)tab_entry.Field(second_field).Get()); }, null); // Дефолтный компаратор??? } current_prime_value = prime_value; start = ii; } } }
// Получение потока всех элементов в отсортированном виде // Альтернатива - выдача всех записей из таблицы Table public IEnumerable <object> GetAll() { PaEntry entry = Table.Element(0); return(index_cell.Root.ElementValues() .Select(va => { long off = (long)((object[])va)[0]; entry.offset = off; return entry.Get(); }) .Where(two => !(bool)((object[])two)[0]) // Проверка на неуничтоженность .Select(two => ((object[])((object[])two)[1]))); }
public void CreateDiscaleDictionary() { gr_discale = new Dictionary <int, Tuple <Diapason, ScaleInMemory> >(); if (Table.Count() == 0) { return; } PaEntry entry = Table.Element(0); long start0 = -1; long start = -1; int key = -1; long sta = -1, num = -1, nscale = -1; foreach (int ind in groups_index.Root.ElementValues()) { start = ind; long off = (long)index_cell.Root.Element(ind).Field(0).Get(); entry.offset = off; if (key != -1) { sta = start0; num = start - start0; nscale = num / 32; ScaleInMemory sim = new ScaleInMemory(index_cell.Root, sta, num, ob => (int)((object[])ob)[2], (int)nscale); sim.Build(); gr_discale.Add(key, new Tuple <Diapason, ScaleInMemory>( new Diapason() { start = sta, numb = num }, sim)); } key = Key1Producer(entry.Get()); start0 = start; } sta = start0; num = index_cell.Root.Count() - start0; nscale = num / 32; ScaleInMemory sim0 = new ScaleInMemory(index_cell.Root, sta, num, ob => (int)((object[])ob)[2], (int)nscale); sim0.Build(); gr_discale.Add(key, new Tuple <Diapason, ScaleInMemory>( new Diapason() { start = sta, numb = num }, sim0)); }
public XElement GetItemByIdBasic(string id, bool addinverse) { PaEntry ent = id_index.GetFirst(id); object[] item = (object[])ent.Get(); XElement res = new XElement("record", new XAttribute("id", item[1]), new XAttribute("type", item[2]), ((object[])item[3]).Cast <object[]>().Select(v3 => new XElement("field", new XAttribute("prop", v3[0]), string.IsNullOrEmpty((string)v3[2]) ? null : new XAttribute(ONames.xmllang, v3[2]), v3[1])), ((object[])item[4]).Cast <object[]>().Select(v2 => new XElement("direct", new XAttribute("prop", v2[0]), v2[1])), null); if (addinverse) { //var qu = inverse_index.GetAll(id) // .Select(pair => // { // return new XElement("inverse", new XAttribute("prop", pair.stri), // new XElement("record", new XAttribute("id", pair.entr.Field(1).Get()))); // }); //res.Add(qu); string predicate = null; XElement inverse = null; foreach (var qq in inverse_index.GetAll(id)) { string pred = qq.stri; if (pred != predicate) { res.Add(inverse); inverse = new XElement("inverse", new XAttribute("prop", pred)); predicate = pred; } string idd = (string)qq.entr.Field(1).Get(); inverse.Add(new XElement("record", new XAttribute("id", idd))); } res.Add(inverse); } return(res); }
protected virtual void AddInIndex(PaEntry entry) { int node; if (entry.Type.Vid == PTypeEnumeration.integer) { node = (int)entry.Get(); searchIndex.Add(node, entry.offset); } else { node = (int)entry.Field(0).Get(); searchIndex.Add(node, entry.offset); foreach (var chiledEntry in entry.Field(1).Elements()) { AddInIndex(chiledEntry); } } }
public IEnumerable <object> GetAllInDiap(Diapason dia) { if (dia.IsEmpty()) { return(Enumerable.Empty <object>()); } PaEntry entry = Table.Element(0); var query2 = index_cell.Root.ElementValues(dia.start, dia.numb) .Select(va => { long off = (long)((object[])va)[0]; entry.offset = off; return(entry.Get()); }) .Where(two => !(bool)((object[])two)[0]) .Select(two => ((object[])((object[])two)[1])); return(query2); }
public string GetName(int code) { Open(true); if (Count == 0) { return(string.Empty); } if (code == int.MinValue) { return(string.Empty); } if (Count <= code) { return(string.Empty); } ncEntry = encodedCell.Root.Element(0); ncEntry.offset = (long)c_index.Root.Element(code).Get(); return(staticFreqEncoding.Decode(((object[])ncEntry.Get()).Cast <byte>().ToArray())); }
public PaEntry GetFirst(Func <PaEntry, int> elementDepth) { if (table.Count() == 0) { return(new PaEntry(null, Int64.MinValue, null)); } PaEntry entry = table.Element(0); PaEntry entry_in_index = index_cell.Root.BinarySearchFirst(ent => { long off = (long)ent.Get(); entry.offset = off; return(elementDepth(entry.Field(i_field))); }); if (entry_in_index.offset == Int64.MinValue) { return(entry_in_index); // не найден } entry.offset = (long)entry_in_index.Get(); return(entry); }
protected override void AddInIndex(PaEntry entry) { int node; if (entry.Type.Vid == PTypeEnumeration.integer) { node = (int) entry.Get(); if (!searchIndex.ContainsKey(node)) searchIndex.Add(node, entry.offset); } else { node = (int) entry.Field(0).Get(); if (!searchIndex.ContainsKey(node)) searchIndex.Add(node, entry.offset); foreach (var chiledEntry in entry.Field(1).Elements()) { AddInIndex(chiledEntry); } } }
private Dictionary <Tkey, List <PaEntry> > keyents = new Dictionary <Tkey, List <PaEntry> >(); // стандартно public void OnAppendElement(PaEntry entry) { Tkey key = KeyProducer(entry.Get()); if (_unique) { keyent.Add(key, entry); // Надо бы что-то проверить... } else { List <PaEntry> entset; if (keyents.TryGetValue(key, out entset)) { entset.Add(entry); } else { keyents.Add(key, Enumerable.Repeat <PaEntry>(entry, 1).ToList()); } } }
public IEnumerable <PaEntry> GetAllByKey(long start, long number, Tkey key) { if (Table == null || Table.Count() == 0) { return(Enumerable.Empty <PaEntry>()); } PaEntry entry = Table.Element(0); PaEntry entry1 = entry; var query = index_cell.Root.BinarySearchAll(start, number, ent => { long off = (long)ent.Get(); entry.offset = off; return(KeyProducer((object[])entry.Get()).CompareTo(key)); }); return(query.Select(ent => { entry1.offset = (long)ent.Get(); return entry1; })); }
internal IEnumerable <Literal> GetDataBySubjPred0(int subj, int pred) { var rec_ent = tree_fix.Root.BinarySearchFirst(ent => ((int)ent.Field(0).Get()).CompareTo(subj)); if (rec_ent.IsEmpty) { return(Enumerable.Empty <Literal>()); } var fields = (object[])rec_ent.Field(1).Get(); PaEntry lit_ent = literals.Root.Element(0); var offsets = fields.Where(pair => (int)((object[])pair)[0] == pred) .Select(pair => (long)((object[])pair)[1]); var lits = offsets.Select(off => { lit_ent.offset = off; object[] pair = (object[])lit_ent.Get(); return(new Literal(pair)); }); return(lits); }
internal IEnumerable <Literal> GetDataBySubjPred1(int subj, int pred) { record rec; if (!codeRec.TryGetValue(subj, out rec)) { return(Enumerable.Empty <Literal>()); } var offsets = rec.fields .Where(pair => pair.Key == pred) .Select(pair => pair.Value); PaEntry lit_ent = literals.Root.Element(0); var lits = offsets.Select(off => { lit_ent.offset = off; object[] pair = (object[])lit_ent.Get(); return(new Literal(pair)); }); return(lits); }
public IEnumerable <PaEntry> GetAllByKey2(long start, long number, Tkey key) { if (Table == null || Table.Count() == 0) { return(Enumerable.Empty <PaEntry>()); } PaEntry entry = Table.Element(0); PaEntry entry1 = entry; int hkey = HalfProducer(key); var entries = index_cell.Root.ElementValues(start, number) .Cast <object[]>() .TakeWhile(va => (int)va[0] <= hkey) .Where(va => (int)va[0] == hkey) .Select(va => { long off = (long)va[1]; entry.offset = off; return(entry); }) .Where(va => { var ka = KeyProducer(entry.Get()); return(ka.CompareTo(key) == 0); }); return(entries); }
public XElement GetPortraitByIdIn(int id, string type) { PaEntry entry = PaEntry.Empty; if (type == "person") { entry = index_persons_id.GetFirstByKey0(id); } else if (type == "photo-doc") { entry = index_photo_docs_id.GetFirstByKey0(id); } if (entry.IsEmpty) { return(null); } object[] val = (object[])entry.Get(); var res = new XElement("record", new XAttribute("id", id), new XAttribute("type", type), new XElement("field", new XAttribute("prop", "name"), (string)val[1]), null); if (type == "person") { foreach (PaEntry ent in index_reflection_reflected.GetAllByKey(id)) { object[] reflect_obj = (object[])ent.Get(); int cod = (int)reflect_obj[3]; XElement port = GetPortraitByIdIn(cod, "photo-doc"); res.Add(new XElement("inverse", new XAttribute("prop", "reflected"), new XElement("record", new XAttribute("id", reflect_obj[0]), new XElement("field", new XAttribute("prop", "ground"), reflect_obj[1]), new XElement("direct", new XAttribute("prop", "in-doc"), port), null))); } } return(res); }
public void Compress(PaCell dtriplets, PredicatesCoding predicatesCoding) { stringsArhive.WriteCell(); PaEntry paEntry = stringsCell.Root.Element(0); foreach (var dtripletElement in dtriplets.Root.Elements()) { int predicateCode = (int)dtripletElement.Field(1).Get(); if (predicatesCoding.LiteralVid[predicateCode] == LiteralVidEnumeration.text) { PaEntry offsetElement = dtripletElement.Field(2); long offset = (long)offsetElement.Get(); paEntry.offset = offset; object[] stri_lang = (object[])paEntry.Get(); offsetElement.Set( StringsArchedCell.Root.AppendElement(new object[] { Enumerable.Cast <object>(stringsArhive.Compress((string)stri_lang[0])).ToArray(), Enumerable.Cast <object>(stringsArhive.Compress((string)stri_lang[01])).ToArray() })); } } StringsArchedCell.Flush(); }
public static void Main(string[] args) { Random rnd = new Random(); string path = @"..\..\..\Databases\"; PType tp_oprops = new PTypeSequence(new PTypeRecord( new NamedType("subject", new PType(PTypeEnumeration.integer)), new NamedType("predicate", new PType(PTypeEnumeration.integer)), new NamedType("object", new PType(PTypeEnumeration.integer)))); PType tp_subject_index = new PTypeSequence(new PType(PTypeEnumeration.longinteger)); PaCell oprops = new PaCell(tp_oprops, path + "opreps.pac", false); PaCell subject_index = new PaCell(tp_subject_index, path + "subj_ind.pac", false); Console.WriteLine("Start"); DateTime tt0 = DateTime.Now; bool toload = true; if (toload) { oprops.Clear(); subject_index.Clear(); oprops.Fill(new object[0]); subject_index.Fill(new object[0]); for (int i = 0; i < 100000000; i++) { object[] valu = new object[] { rnd.Next(), rnd.Next(), 999 }; long offset = oprops.Root.AppendElement(valu); subject_index.Root.AppendElement(offset); if (i % 1000000 == 0) { Console.Write(" " + i); } } Console.WriteLine(); int[][] samples = { new int[] { 777, 21 }, new int[] { 777, 19 }, new int[] { 777, 22 }, new int[] { 7777777, 21 }, new int[] { 777, 18 } }; foreach (int[] sa in samples) { object[] valu = new object[] { sa[0], sa[1], 999 }; long offset = oprops.Root.AppendElement(valu); subject_index.Root.AppendElement(offset); } oprops.Flush(); subject_index.Flush(); Console.WriteLine("Loading ok. duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now; PaEntry.bufferBytes = 400000000; PaEntry oentry = oprops.Root.Element(0); //subject_index.Root.SortByKey<int>(off => //{ // oentry.offset = (long)off; // return (int)oentry.Field(0).Get(); //}); subject_index.Root.SortByKey <PairInt>(off => { oentry.offset = (long)off; object[] triple = (object[])oentry.Get(); return(new PairInt() { first = (int)triple[0], second = (int)triple[1] }); }); Console.WriteLine("Sort ok. duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now; } PaEntry oentry2 = oprops.Root.Element(0); var query = subject_index.Root.BinarySearchAll(ent => { long off = (long)ent.Get(); oentry2.offset = off; int sub = (int)oentry2.Field(0).Get(); return(sub.CompareTo(777)); }); Console.WriteLine("BinarySearch ok. duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now; foreach (var ent in query) { oentry2.offset = (long)ent.Get(); object[] valu = (object[])oentry2.Get(); Console.WriteLine("{0} {1} {2}", valu[0], valu[1], valu[2]); } Console.WriteLine("Finish. duration=" + (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now; }