EdgeId NewEdgeId(Graph g) { Range <EdgeId> range; EdgeId eId = 1; switch (edgeRanges.Count) { case 0: range = new Range <EdgeId>(1, 1); edgeRanges.Add(range); break; case 1: range = edgeRanges.First(); if (range.Min == 1) { eId = range.Max + 1; range = new Range <EdgeId>(1, eId); } else { eId = range.Min - 1; range = new Range <EdgeId>(eId, range.Max); } edgeRanges[0] = range; break; default: { range = edgeRanges.First(); if (range.Min > 1) { eId = range.Min - 1; range = new Range <VertexId>(eId, range.Max); } else { Range <VertexId> nextRange = edgeRanges[1]; if (range.Max + 2 == nextRange.Min) { edgeRanges.Remove(range); eId = range.Max + 1; range = new Range <VertexId>(range.Min, nextRange.Max); } else { range = new Range <VertexId>(range.Min, range.Max + 1); eId = range.Max + 1; } edgeRanges.Add(range); } } break; } return(eId); }
static void CreateData() { using (SessionNoServer session = new SessionNoServer(s_systemDir)) { bool dirExist = Directory.Exists(session.SystemDirectory); if (dirExist) Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases. Directory.CreateDirectory(session.SystemDirectory); File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb")); DataCache.MaximumMemoryUse = 10000000000; // 10 GB, set this to what fits your case SessionBase.DefaultCompressPages = PageInfo.compressionKind.LZ4; session.BeginUpdate(); BTreeMap<Int64, VelocityDbList<Person>> btreeMap = new BTreeMap<Int64, VelocityDbList<Person>>(null, session); session.Persist(btreeMap); for (int i = 0; i < 100000; i++) { Person p = new Person(); GeoHash geohash = GeoHash.WithBitPrecision(p.Lattitude, p.Longitude); VelocityDbList<Person> personList; if (btreeMap.TryGetValue(geohash.LongValue, out personList)) personList.Add(p); else { personList = new VelocityDbList<Person>(1); //session.Persist(p); personList.Add(p); session.Persist(personList); btreeMap.Add(geohash.LongValue, personList); } } session.Commit(); } }
public Person(Person person = null) // creates a random Person object { int r = randGen.Next(99999); firstName = r.ToString(); r = randGen.Next(99999999); lastName = r.ToString(); VelocityDbList<Person> personList = new VelocityDbList<Person>(); if (person != null && person.IsPersistent) { personList.Persist(person.Session, person); personList.Add(person); friendsRef = new WeakIOptimizedPersistableReference<VelocityDbList<Person>>(personList); } }
public Person(string firstName, string lastName, UInt16 age, long ssn, Person bestFriend, Person spouse) { m_firstName = firstName; m_lastName = lastName; m_age = age; m_ssn = ssn; if (spouse != null) m_spouse = new WeakIOptimizedPersistableReference<Person>(spouse); m_pets = new List<Pet>(); m_friends = new VelocityDbList<WeakIOptimizedPersistableReference<Person>>(0); if (bestFriend != null) { m_bestFriend = new WeakIOptimizedPersistableReference<Person>(bestFriend); m_friends.Add(new WeakIOptimizedPersistableReference<Person>(bestFriend)); } }
public Person(Person person = null) // creates a random Person object { int r = randGen.Next(99999); firstName = r.ToString(); r = randGen.Next(99999999); lastName = r.ToString(); VelocityDbList <Person> personList = new VelocityDbList <Person>(); if (person != null && person.IsPersistent) { personList.Persist(person.Session, person); personList.Add(person); friendsRef = new WeakIOptimizedPersistableReference <VelocityDbList <Person> >(personList); } }
public Person(string firstName, string lastName, UInt16 age, long ssn, Person bestFriend, Person spouse) { m_firstName = firstName; m_lastName = lastName; m_age = age; m_ssn = ssn; if (spouse != null) { m_spouse = new WeakIOptimizedPersistableReference <Person>(spouse); } m_pets = new List <Pet>(); m_friends = new VelocityDbList <WeakIOptimizedPersistableReference <Person> >(0); if (bestFriend != null) { m_bestFriend = new WeakIOptimizedPersistableReference <Person>(bestFriend); m_friends.Add(new WeakIOptimizedPersistableReference <Person>(bestFriend)); } }
public StoreProducts(string path) { fileName = path.Substring(0, path.LastIndexOf(".txt")); fileName = fileName.Substring(path.LastIndexOf(Path.DirectorySeparatorChar) + 1); productList = new VelocityDbList <StoreProduct>(); StreamReader stream = new StreamReader(path); try { storeName = stream.ReadLine(); description = stream.ReadLine(); image = stream.ReadLine(); link = stream.ReadLine(); string t = stream.ReadLine(); stars = Int16.Parse(t); StoreProduct c = new StoreProduct(storeName); t = stream.ReadLine(); while (t != null) { if (t != null && t.Length > 0) { c.expireDate = DateTime.Parse(t); } else { c.expireDate = DateTime.MaxValue; } c.name = stream.ReadLine(); c.description = stream.ReadLine(); c.image = stream.ReadLine(); c.link = stream.ReadLine(); productList.Add(c); c = new StoreProduct(storeName); t = stream.ReadLine(); } stream.Close(); } catch (Exception ex) { Console.WriteLine(ex); stream.Close(); } }
static void CreateData() { using (SessionNoServer session = new SessionNoServer(s_systemDir)) { bool dirExist = Directory.Exists(session.SystemDirectory); if (dirExist) { Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases. } Directory.CreateDirectory(session.SystemDirectory); File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb")); DataCache.MaximumMemoryUse = 10000000000; // 10 GB, set this to what fits your case SessionBase.DefaultCompressPages = PageInfo.compressionKind.LZ4; session.BeginUpdate(); BTreeMap <Int64, VelocityDbList <Person> > btreeMap = new BTreeMap <Int64, VelocityDbList <Person> >(null, session); session.Persist(btreeMap); for (int i = 0; i < 100000; i++) { Person p = new Person(); GeoHash geohash = GeoHash.WithBitPrecision(p.Lattitude, p.Longitude); VelocityDbList <Person> personList; if (btreeMap.TryGetValue(geohash.LongValue, out personList)) { personList.Add(p); } else { personList = new VelocityDbList <Person>(1); //session.Persist(p); personList.Add(p); session.Persist(personList); btreeMap.Add(geohash.LongValue, personList); } } session.Commit(); } }
public StoreCoupons(string path) { fileName = path.Substring(0, path.LastIndexOf(".txt")); fileName = fileName.Substring(path.LastIndexOf(Path.DirectorySeparatorChar) + 1); couponList = new VelocityDbList <Coupon>(); StreamReader stream = new StreamReader(path); try { name = stream.ReadLine(); description = stream.ReadLine(); image = stream.ReadLine(); link = stream.ReadLine(); string t = stream.ReadLine(); stars = Int16.Parse(t); Coupon c = new Coupon(); c.Category = stream.ReadLine(); while (c.Category != null && !c.Category.Equals(".")) { t = stream.ReadLine(); if (t != null && t.Length > 0) { c.StartDate = DateTime.Parse(t); } else { c.StartDate = DateTime.MinValue; } t = stream.ReadLine(); if (t != null && t.Length > 0) { DateTime dt; DateTime.TryParse(t, out dt); c.ExpireDate = dt; } else { c.ExpireDate = DateTime.MaxValue; } t = stream.ReadLine(); if (t != null && t.Length > 0) { c.PromotionalType = Int16.Parse(t); } else { c.PromotionalType = 0; } c.Description = stream.ReadLine(); t = stream.ReadLine(); if (t.CompareTo("inLinkActivated") == 0) { c.Code = null; } else { c.Code = t; } c.Image = stream.ReadLine(); c.Link = stream.ReadLine(); couponList.Add(c); c = new Coupon(); c.Category = stream.ReadLine(); } stream.Close(); } catch (Exception ex) { Console.WriteLine(ex); stream.Close(); } }
internal VertexId AllocateVertexId(VertexId vId = 0, VelocityDbList <Range <VertexId> > vertecis = null) { if (vertecis == null) { if (this.vertecis == null) { return(vId); } vertecis = this.vertecis; } Range <VertexId> range; if (vId != 0) { range = new Range <VertexId>(vId, vId); if (vertecis.Count == 0) { vertecis.Add(range); } else { bool isEqual; int pos = vertecis.BinarySearch(range, out isEqual); int originalPos = pos; if (isEqual) { throw new VertexAllreadyExistException("Vertex with id " + vId + " allready exist"); } Range <VertexId> existingRange = vertecis[pos == vertecis.Count ? pos - 1 : pos]; if (existingRange.Min == 0 && existingRange.Max == 0 || (pos > 0 && existingRange.Min > vId + 1)) { existingRange = vertecis[--pos]; } if (existingRange.Min - 1 == vId) { range = new Range <VertexId>(existingRange.Min - 1, existingRange.Max); if (pos > 0) { Range <VertexId> priorRange = vertecis[pos - 1]; if (priorRange.Max + 1 == range.Min) { range = new Range <VertexId>(priorRange.Min, range.Max); vertecis[pos - 1] = range; vertecis.RemoveAt(pos); } else { vertecis[pos] = range; } } else { vertecis[pos] = range; } } else if (existingRange.Max + 1 == vId) { range = new Range <VertexId>(existingRange.Min, existingRange.Max + 1); if (vertecis.Count > pos) { Range <VertexId> nextRange = vertecis[pos + 1]; if (nextRange.Min == range.Max + 1) { range = new Range <VertexId>(range.Min, nextRange.Max); vertecis.RemoveAt(pos); vertecis[pos] = range; } else { vertecis[pos] = range; } } else { vertecis[pos == vertecis.Count ? pos - 1 : pos] = range; } } else if (vId >= existingRange.Min && vId <= existingRange.Max) { throw new VertexAllreadyExistException("Vertex with id " + vId + " allready exist"); } else { vertecis.Insert(originalPos, range); } #if VERIFY int i = 0; Range <VertexId> p = default(Range <VertexId>); foreach (Range <VertexId> r in vertecis) { if (i++ > 0) { if (p.Min >= r.Min) { throw new UnexpectedException("Wrong order"); } if (p.Max == r.Min + 1) { throw new UnexpectedException("Failed to merge"); } } p = r; } #endif } } else { vId = 1; switch (vertecis.Count) { case 0: range = new Range <VertexId>(1, 1); vertecis.Add(range); break; case 1: range = vertecis.First(); if (range.Min == 1) { vId = range.Max + 1; range = new Range <VertexId>(1, vId); } else { vId = range.Min - 1; range = new Range <VertexId>(vId, range.Max); } vertecis[0] = range; break; default: { range = vertecis.First(); if (range.Min > 1) { vId = range.Min - 1; range = new Range <VertexId>(vId, range.Max); vertecis[0] = range; } else { Range <VertexId> nextRange = vertecis[1]; if (range.Max + 1 == nextRange.Min) { vertecis.RemoveAt(1); vId = nextRange.Min; range = new Range <VertexId>(range.Min, nextRange.Max); vertecis[0] = range; } else { range = new Range <VertexId>(range.Min, range.Max + 1); vId = range.Max; vertecis[0] = range; } } } break; } } return(vId); }