Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new edge type.
 /// </summary>
 /// <param name="aTypeId">The id to use for the new edge type</param>
 /// <param name="aTypeName">A type name to use</param>
 /// <param name="tailType">Restrict tail vertex to a certain vertex type</param>
 /// <param name="headType">Restrict head vertex to a certain vertex type</param>
 /// <param name="birectional">Is this edge type bidirectional (going both ways)</param>
 /// <param name="baseType">A base type can be specified</param>
 /// <param name="graph">The owning graph</param>
 public EdgeType(TypeId aTypeId, string aTypeName, VertexType tailType, VertexType headType, bool birectional, EdgeType baseType, Graph graph)
 {
     this.graph    = graph;
     this.baseType = baseType;
     subType       = new VelocityDbList <EdgeType>();
     if (baseType != null)
     {
         baseType.subType.Add(this);
     }
     this.birectional = birectional;
     typeId           = aTypeId;
     typeName         = aTypeName;
     this.tailType    = tailType;
     this.headType    = headType;
     if (Unrestricted)
     {
         unrestrictedEdges = new BTreeMap <EdgeId, UnrestrictedEdge>(null, graph.Session);
     }
     else
     {
         restrictedEdges = new BTreeMap <EdgeId, ulong>(null, graph.Session);
     }
     stringToPropertyType = new BTreeMap <string, PropertyType>(null, graph.Session);
     edgeRanges           = new VelocityDbList <Range <EdgeId> >();
 }
Ejemplo n.º 2
0
 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();
   }
 }
 internal PropertyTypeNoDuplicateValues(bool isVertexProp, TypeId typeId, PropertyId propertyId, string name, PropertyKind kind, Graph graph)
     : base(isVertexProp, typeId, propertyId, name, kind, graph)
 {
     m_valueToId = new BTreeMap <T, UInt64>(null, graph.Session);
     m_IdToValue = new BTreeMap <UInt64, T>(null, graph.Session);
     m_nextId    = 0;
 }
Ejemplo n.º 4
0
 public Lexicon(SessionBase session, HashCodeComparer <TokenType <T> > hashCodeComparer)
 {
     _valueToId = new BTreeMap <T, UInt32>(null, session);
     _IdToValue = new BTreeMap <UInt32, T>(null, session);
     _nextId    = 0;
     _tokenMap  = new BTreeMap <UInt32, BTreeSet <StoreBase> >(null, session);
 }
Ejemplo n.º 5
0
 public Lexicon(ushort nodeSize, SessionBase session)
 {
     _valueToId       = new BTreeMap <T, UInt32>(null, session);
     _IdToValue       = new BTreeMap <UInt32, T>(null, session);
     _idToGlobalCount = new BTreeMap <uint, uint>(null, session);
     _nextId          = 0;
     _tokenMap        = new BTreeMap <UInt32, BTreeSet <Document> >(null, session);
 }
Ejemplo n.º 6
0
 public AspNetIdentity(SessionBase session)
 {
   m_adapterMap = new BTreeMap<string, UserLoginInfoAdapter>(null, session);
   m_userSet = new BTreeSet<IdentityUser>(null, session);
   m_roleSet = new BTreeSet<IdentityRole>(null, session);
   m_emailToId = new BTreeMap<string, ulong>(null, session);
   m_userNameToId = new BTreeMap<string, ulong>(null, session);
 }
Ejemplo n.º 7
0
 public AspNetIdentity(SessionBase session)
 {
     m_adapterMap   = new BTreeMap <string, UserLoginInfoAdapter>(null, session);
     m_userSet      = new BTreeSet <IdentityUser>(null, session);
     m_roleSet      = new BTreeSet <IdentityRole>(null, session);
     m_emailToId    = new BTreeMap <string, ulong>(null, session);
     m_userNameToId = new BTreeMap <string, ulong>(null, session);
 }
Ejemplo n.º 8
0
    // Please help, I have not figured out how to properly do the triangle query using LINQ
    static int queryUsingLINQ(BTreeMap<int, int[]> edges)
    {
      int[] edge2values = null;

      int r = (from KeyValuePair<int, int[]> edge in edges
               from int edgeTo1 in edge.Value 
               where edge.Key < edgeTo1
               from int edgeTo2 in edge.Value
               where edge.Key < edgeTo2 && edgeTo2 > edgeTo1 && edges.TryGetValue(edgeTo1, out edge2values) && Array.BinarySearch(edge2values, edgeTo2) >= 0
               select edge).Count();
      return r;
    }
Ejemplo n.º 9
0
        // Please help, I have not figured out how to properly do the triangle query using LINQ
        static int queryUsingLINQ(BTreeMap <int, int[]> edges)
        {
            int[] edge2values = null;

            int r = (from KeyValuePair <int, int[]> edge in edges
                     from int edgeTo1 in edge.Value
                     where edge.Key < edgeTo1
                     from int edgeTo2 in edge.Value
                     where edge.Key <edgeTo2 && edgeTo2> edgeTo1 && edges.TryGetValue(edgeTo1, out edge2values) && Array.BinarySearch(edge2values, edgeTo2) >= 0
                     select edge).Count();

            return(r);
        }
Ejemplo n.º 10
0
 internal VertexType(TypeId aTypeId, string aTypeName, VertexType baseType, Graph graph)
 {
   this.graph = graph;
   this.baseType = baseType;
   subType = new VelocityDbList<VertexType>();
   if (baseType != null)
     baseType.subType.Add(this);
   typeId = (TypeId)aTypeId;
   typeName = aTypeName;
   vertecis = new VelocityDbList<Range<VertexId>>();
   stringToPropertyType = new BTreeMap<string, PropertyType>(null, graph.Session);
   edgeTypes = new BTreeSet<EdgeType>(null, graph.Session);
   tailToHeadEdges = new BTreeMap<EdgeType, BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>>>(null, graph.Session);
   headToTailEdges = new BTreeMap<EdgeType, BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>>>(null, graph.Session);
 }
Ejemplo n.º 11
0
        internal PropertyTypeT(bool isVertexProp, TypeId typeId, PropertyId propertyId, string name, PropertyKind kind, Graph graph)
            : base(isVertexProp, typeId, propertyId, name, graph)
        {
            m_propertyValue = new BTreeMap <ElementId, T>(null, graph.Session);
            switch (kind)
            {
            case PropertyKind.Indexed:
                m_valueIndex = new BTreeMap <T, BTreeSet <ElementId> >(null, graph.Session);
                break;

            case PropertyKind.Unique:
                m_valueIndexUnique = new BTreeMap <T, ElementId>(null, graph.Session);
                break;
            }
        }
Ejemplo n.º 12
0
        static int discoverTrianglesSingleCore(BTreeMap <int, int[]> edges)
        {
            int triangles = 0;
            BTreeMapIterator <int, int[]> edgesItr = edges.Iterator();

            while (edgesItr.MoveNext())
            {
                int   nodeId = edgesItr.CurrentKey();
                int[] edge = edgesItr.CurrentValue();
                int   stop = edge.Length - 1;
                int   i = stop;
                int   edgeToStart, edgeTo;
                int   pos;
                while (i >= 0)
                {
                    int[] edgeInfo2;
                    edgeToStart = edge[i--];
                    if (nodeId < edgeToStart)
                    {
                        if (edges.TryGetValue(edgeToStart, out edgeInfo2))
                        {
                            for (int j = stop; j >= i; j--)
                            {
                                edgeTo = edge[j];
                                if (edgeToStart < edgeTo)
                                {
                                    pos = Array.BinarySearch <int>(edgeInfo2, edgeTo);
                                    if (pos >= 0)
                                    { // we know this one is connected to edgeInfo.From because it is part of edgeInfo.To
                                        triangles++;
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return(triangles);
        }
Ejemplo n.º 13
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
     const UInt32 numberOfPersons = 10000;
     const ushort nodeMaxSize = 5000;
     const ushort comparisonByteArraySize = sizeof(UInt64); // enough room to hold entire idNumber of a Person
     const bool comparisonArrayIsCompleteKey = true;
     const bool addIdCompareIfEqual = false;
     Person person;
     session.BeginUpdate();
     session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.None;
     //mySession.SetTraceAllDbActivity();
     BTreeSet<string> stringSet = new BTreeSet<string>(null, session);
     BTreeSetOidShort<string> stringSetShort = new BTreeSetOidShort<string>(null, session);
     BTreeMap<string, string> stringMap = new BTreeMap<string, string>(null, session);
     BTreeMapOidShort<string, string> stringMapShort = new BTreeMapOidShort<string, string>(null, session);
     CompareByField<Person> compareByField = new CompareByField<Person>("idNumber", session, addIdCompareIfEqual);
     BTreeSet<Person> bTree = new BTreeSet<Person>(compareByField, session, nodeMaxSize, comparisonByteArraySize, comparisonArrayIsCompleteKey);
     session.Persist(bTree); // Persist the root of the BTree so that we have something persisted that can be flushed to disk if memory available becomes low
     for (int i = 0; i < numberOfPersons; i++)
     {
       person = new Person();
       // session.Persist(person);
       bTree.AddFast(person);
     }
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.UseExternalStorageApi = true;
     session.BeginRead();
     BTreeSet<Person> bTree = session.AllObjects<BTreeSet<Person>>().First();
     foreach (Person person in (IEnumerable<Person>)bTree)
     {
       if (person.IdNumber > 196988888791402)
       {
         Console.WriteLine(person);
         break;
       }
     }
     session.Commit();
   }
 }
Ejemplo n.º 14
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
         const UInt32 numberOfPersons              = 10000;
         const ushort nodeMaxSize                  = 5000;
         const ushort comparisonByteArraySize      = sizeof(UInt64); // enough room to hold entire idNumber of a Person
         const bool   comparisonArrayIsCompleteKey = true;
         const bool   addIdCompareIfEqual          = false;
         Person       person;
         session.BeginUpdate();
         session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.None;
         //mySession.SetTraceAllDbActivity();
         BTreeSet <string>                 stringSet      = new BTreeSet <string>(null, session);
         BTreeSetOidShort <string>         stringSetShort = new BTreeSetOidShort <string>(null, session);
         BTreeMap <string, string>         stringMap      = new BTreeMap <string, string>(null, session);
         BTreeMapOidShort <string, string> stringMapShort = new BTreeMapOidShort <string, string>(null, session);
         CompareByField <Person>           compareByField = new CompareByField <Person>("idNumber", session, addIdCompareIfEqual);
         BTreeSet <Person>                 bTree          = new BTreeSet <Person>(compareByField, session, nodeMaxSize, comparisonByteArraySize, comparisonArrayIsCompleteKey);
         session.Persist(bTree); // Persist the root of the BTree so that we have something persisted that can be flushed to disk if memory available becomes low
         for (int i = 0; i < numberOfPersons; i++)
         {
             person = new Person();
             // session.Persist(person);
             bTree.AddFast(person);
         }
         session.Commit();
     }
     using (SessionNoServer session = new SessionNoServer(systemDir))
     {
         session.UseExternalStorageApi = true;
         session.BeginRead();
         BTreeSet <Person> bTree = session.AllObjects <BTreeSet <Person> >().First();
         foreach (Person person in (IEnumerable <Person>)bTree)
         {
             if (person.IdNumber > 196988888791402)
             {
                 Console.WriteLine(person);
                 break;
             }
         }
         session.Commit();
     }
 }
Ejemplo n.º 15
0
 static int discoverTrianglesSingleCore(BTreeMap<int, int[]> edges)
 {
   int triangles = 0;
   BTreeMapIterator<int, int[]> edgesItr = edges.Iterator();
   while (edgesItr.MoveNext())
   {
     int nodeId = edgesItr.CurrentKey();
     int[] edge = edgesItr.CurrentValue();
     int stop = edge.Length - 1;
     int i = stop;
     int edgeToStart, edgeTo;
     int pos;
     while (i >= 0)
     {
       int[] edgeInfo2;
       edgeToStart = edge[i--];
       if (nodeId < edgeToStart)
       {
         if (edges.TryGetValue(edgeToStart, out edgeInfo2))
         {
           for (int j = stop; j >= i; j--)
           {
             edgeTo = edge[j];
             if (edgeToStart < edgeTo)
             {
               pos = Array.BinarySearch<int>(edgeInfo2, edgeTo);
               if (pos >= 0)
               { // we know this one is connected to edgeInfo.From because it is part of edgeInfo.To
                 triangles++;
               }
             }
             else
               break;
           }
         }
       }
       else
         break;
     }
   }
   return triangles;
 }
Ejemplo n.º 16
0
 internal VertexType(TypeId aTypeId, string aTypeName, VertexType baseType, Graph graph)
 {
   m_graph = new WeakIOptimizedPersistableReference<Graph>(graph);
   m_baseType = baseType;
   m_subTypes = new List<VertexType>();
   if (baseType != null)
   {
     baseType.Update();
     baseType.m_subTypes.Add(this);
   }
   m_typeId = (TypeId)aTypeId;
   m_typeName = aTypeName;
   var vertices = new VelocityDbList<Range<VertexId>>();
   graph.Session.Persist(vertices);
   m_vertices = new WeakIOptimizedPersistableReference<VelocityDbList<Range<VertexId>>>(vertices);
   m_stringToPropertyType = new BTreeMap<string, PropertyType>(null, graph.Session);
   m_edgeTypes = new BTreeSet<EdgeType>(null, graph.Session);
   m_tailToHeadEdges = new BTreeMap<EdgeType, BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>>>(null, graph.Session);
   m_headToTailEdges = new BTreeMap<EdgeType, BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>>>(null, graph.Session);
   graph.Session.Persist(this);
 }
Ejemplo n.º 17
0
        public void aCreateDefaultCompareIntKeyIntValue(int number)
        {
            Oid id;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                Placement place = new Placement((UInt32)number, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
                session.Compact();
                session.BeginUpdate();
                BTreeMap <int, int> bTree = new BTreeMap <int, int>(null, session);
                bTree.Persist(place, session);
                id = bTree.Oid;
                for (int i = 0; i < number; i++)
                {
                    bTree.Add(i, i + 1);
                }
                bTree.Clear();
                for (int i = 0; i < number; i++)
                {
                    bTree.Add(i, i + 1);
                }
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                BTreeMap <int, int> bTree = (BTreeMap <int, int>)session.Open(id);
                int count = 0;
                int prior = 0;
                foreach (KeyValuePair <int, int> pair in bTree)
                {
                    count++;
                    Assert.True(pair.Key == prior++);
                    Assert.True(pair.Key == pair.Value - 1);
                }
                Assert.True(number == count);
                session.Commit();
            }
        }
Ejemplo n.º 18
0
        public void Rajan()
        {
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                session.Persist("A");
                session.Persist("B");
                session.Persist("C");
                Placement place = new Placement(900, 1, 1);
                session.Persist("D", place);
                session.Commit();
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                Database db      = session.OpenDatabase(session.DatabaseNumberOf(typeof(string)));
                var      strings = from string str in db.AllObjects <string>() where str.Length > 0 select str;
                foreach (var item in strings)
                {
                    Console.WriteLine(item);
                }
                db      = session.OpenDatabase(900);
                strings = from string str in db.AllObjects <string>() where str.Length > 0 select str;
                foreach (var item in strings)
                {
                    Console.WriteLine(item);
                }
                session.Commit();
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                BTreeMap <string, VelocityDbList <int> > map = new BTreeMap <string, VelocityDbList <int> >(null, session);
                session.Persist(map);
                session.Commit();
            }
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Creates a new <see cref="Graph"/>
 /// </summary>
 /// <param name="session">The active session</param>
 /// <param name="vertexIdSetPerVertexType">Set to <see langword="false"/> if you want graph wide unique <see cref="Vertex"/> ids, by default <see langword="true"/> each <see cref="VertexType"/> maintains its own set of <see cref="Vertex"/> ids</param>
 public Graph(SessionBase session, bool vertexIdSetPerVertexType = true)
 {
     flags              = 0;
     edgeTypeCt         = 0;
     vertexTypeCt       = 0;
     stringToVertexType = new BTreeMap <string, VertexType>(null, session);
     vertexType         = new VertexType[0];
     stringToEdgeType   = new BTreeMap <string, EdgeType>(null, session);
     if (vertexIdSetPerVertexType)
     {
         flags += (UInt32)GraphFlags.VertexIdSetPerType;
     }
     else
     {
         vertexIdToVertexType = new BTreeMap <EdgeTypeId, EdgeTypeId>(null, session);
         vertecis             = new VelocityDbList <Range <VertexId> >();
     }
     edgeType     = new EdgeType[0];
     propertyType = new PropertyType[0];
     this.session = session;
     NewVertexType("default");
     NewEdgeType("default", true); // not sure if we need "directed" or not as edge type parameter ???
 }
Ejemplo n.º 20
0
 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();
     }
 }
Ejemplo n.º 21
0
        public void bCreateDefaultCompareIntKeyPersonValue(int number)
        {
            Oid id;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                Placement place       = new Placement((UInt32)number, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
                Placement personPlace = new Placement((UInt32)number + 1, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
                session.BeginUpdate();
                BTreeMap <int, Person> bTree = new BTreeMap <int, Person>(null, session);
                bTree.Persist(place, session);
                id = bTree.Oid;
                Person person;
                for (int i = 0; i < number; i++)
                {
                    person = new Person();
                    person.Persist(personPlace, session);
                    bTree.Add(i, person);
                }
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                BTreeMap <int, Person> bTree = (BTreeMap <int, Person>)session.Open(id);
                int count = 0;
                int prior = 0;
                foreach (KeyValuePair <int, Person> pair in bTree)
                {
                    count++;
                    Assert.True(pair.Key == prior++);
                    Assert.True(pair.Value != null);
                }
                Assert.True(number == count);
                session.Commit();
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Creates a new edge type.
        /// </summary>
        /// <param name="aTypeId">The id to use for the new edge type</param>
        /// <param name="aTypeName">A type name to use</param>
        /// <param name="tailType">Restrict tail vertex to a certain vertex type</param>
        /// <param name="headType">Restrict head vertex to a certain vertex type</param>
        /// <param name="birectional">Is this edge type bidirectional (going both ways)</param>
        /// <param name="baseType">A base type can be specified</param>
        /// <param name="graph">The owning graph</param>
        public EdgeType(TypeId aTypeId, string aTypeName, VertexType tailType, VertexType headType, bool birectional, EdgeType baseType, Graph graph)
        {
            m_graph    = new WeakIOptimizedPersistableReference <Graph>(graph);
            m_baseType = baseType;
            m_subTypes = new List <EdgeType>();
            if (baseType != null)
            {
                baseType.Update();
                baseType.m_subTypes.Add(this);
            }
            m_birectional = birectional;
            m_typeId      = aTypeId;
            m_typeName    = aTypeName;
            if (tailType != null)
            {
                m_tailType = new WeakIOptimizedPersistableReference <VertexType>(tailType);
            }
            if (headType != null)
            {
                m_headType = new WeakIOptimizedPersistableReference <VertexType>(headType);
            }
            if (Unrestricted)
            {
                m_unrestrictedEdges = new BTreeMap <EdgeId, UnrestrictedEdge>(null, graph.GetSession());
            }
            else
            {
                m_restrictedEdges = new BTreeMap <EdgeId, ulong>(null, graph.GetSession());
            }
            m_stringToPropertyType = new BTreeMap <string, PropertyType>(null, graph.GetSession());
            var edgeRanges = new VelocityDbList <Range <EdgeId> >();

            graph.GetSession().Persist(edgeRanges);
            m_edgeRanges = new WeakIOptimizedPersistableReference <VelocityDbList <Range <PropertyId> > >(edgeRanges);
            graph.GetSession().Persist(this);
        }
Ejemplo n.º 23
0
        }                                   // for lookups

        public Document(string url, IndexRoot indexRoot, SessionBase session)
        {
            _url      = url;
            m_wordHit = new BTreeMap <UInt32, UInt32>(null, session, 50000);
        }
Ejemplo n.º 24
0
 public ActingPerson(string name, SessionBase session)
 {
   this.name = name;
   inMovieAs = new BTreeMap<Movie, string>(null, session);
 }
Ejemplo n.º 25
0
 internal void NewHeadToTailEdge(EdgeType edgeType, Edge edge, Vertex tail, Vertex head, SessionBase session)
 {
   BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>> map;
   BTreeMap<EdgeId, BTreeSet<EdgeIdVertexId>> innerMap;
   BTreeSet<EdgeIdVertexId> set;
   //lock (headToTailEdges)
   {
     if (!m_headToTailEdges.TryGetValue(edgeType, out map))
     {
       map = new BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>>(null, session);
       innerMap = new BTreeMap<EdgeId, BTreeSet<EdgeIdVertexId>>(null, session);
       set = new BTreeSet<EdgeIdVertexId>(null, session);
       innerMap.AddFast(head.VertexId, set);
       map.AddFast(tail.VertexType, innerMap);
       m_headToTailEdges.AddFast(edgeType, map);
       m_edgeTypes.AddFast(edgeType);
     }
     else if (!map.TryGetValue(tail.VertexType, out innerMap))
     {
       innerMap = new BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>(null, session);
       set = new BTreeSet<EdgeIdVertexId>(null, session);
       innerMap.AddFast(head.VertexId, set);
       map.AddFast(tail.VertexType, innerMap);
     }
     else if (!innerMap.TryGetValue(head.VertexId, out set))
     {
       set = new BTreeSet<EdgeIdVertexId>(null, session);
       innerMap.AddFast(head.VertexId, set);
     }
     set.AddFast(edgeVertexId(edge, tail.VertexId));
   }
 }
Ejemplo n.º 26
0
 internal void NewTailToHeadEdge(EdgeType edgeType, Edge edge, Vertex tail, Vertex head, SessionBase session)
 {
   BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>> map;
   BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>> innerMap;
   BTreeSet<EdgeIdVertexId> set;
   //lock (tailToHeadEdges)
   {
     if (!m_tailToHeadEdges.TryGetValue(edgeType, out map))
     {
       map = new BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>>(null, session);
       innerMap = new BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>(null, session);
       set = new BTreeSet<EdgeIdVertexId>(null, session);
       //if (IsPersistent)
       //{
       //  session.Persist(set, 1000);
       //  session.Persist(innerMap, 1000);
       //  session.Persist(map, 1000);
       //}
       innerMap.AddFast(tail.VertexId, set);
       map.AddFast(head.VertexType, innerMap);
       m_tailToHeadEdges.AddFast(edgeType, map);
       m_edgeTypes.AddFast(edgeType);
     }
     else if (!map.TryGetValue(head.VertexType, out innerMap))
     {
       innerMap = new BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>(null, session);
       set = new BTreeSet<EdgeIdVertexId>(null, session);
       //if (IsPersistent)
       //{
       //  session.Persist(set, 1000);
       //  session.Persist(innerMap, 1000);
       //}
       innerMap.AddFast(tail.VertexId, set);
       map.AddFast(head.VertexType, innerMap);
     }
     else if (!innerMap.TryGetValue(tail.VertexId, out set))
     {
       set = new BTreeSet<EdgeIdVertexId>(null, session);
       //if (IsPersistent)
       //{
       //  session.Persist(set, 1000);
       //}
       innerMap.AddFast(tail.VertexId, set);
     }
     set.AddFast(edgeVertexId(edge, head.VertexId));
   }
 }
Ejemplo n.º 27
0
 public void bCreateDefaultCompareIntKeyPersonValue(int number)
 {
   Oid id;
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     Placement place = new Placement((UInt32)number, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
     Placement personPlace = new Placement((UInt32)number + 1, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
     session.BeginUpdate();
     BTreeMap<int, Person> bTree = new BTreeMap<int, Person>(null, session);
     bTree.Persist(place, session);
     id = bTree.Oid;
     Person person;
     for (int i = 0; i < number; i++)
     {
       person = new Person();
       person.Persist(personPlace, session);
       bTree.Add(i, person);
     }
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginRead();
     BTreeMap<int, Person> bTree = (BTreeMap<int, Person>)session.Open(id);
     int count = 0;
     int prior = 0;
     foreach (KeyValuePair<int, Person> pair in bTree)
     {
       count++;
       Assert.True(pair.Key == prior++);
       Assert.True(pair.Value != null);
     }
     Assert.True(number == count);
     session.Commit();
   }
 }
Ejemplo n.º 28
0
 public void aCreateDefaultCompareIntKeyIntValue(int number)
 {
   Oid id;
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     Placement place = new Placement((UInt32)number, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
     session.Compact();
     session.BeginUpdate();
     BTreeMap<int, int> bTree = new BTreeMap<int, int>(null, session);
     bTree.Persist(place, session);
     id = bTree.Oid;
     for (int i = 0; i < number; i++)
     {
       bTree.Add(i, i + 1);
     }
     bTree.Clear();
     for (int i = 0; i < number; i++)
     {
       bTree.Add(i, i + 1);
     }
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginRead();
     BTreeMap<int, int> bTree = (BTreeMap<int, int>)session.Open(id);
     int count = 0;
     int prior = 0;
     foreach (KeyValuePair<int, int> pair in bTree)
     {
       count++;
       Assert.True(pair.Key == prior++);
       Assert.True(pair.Key == pair.Value - 1);
     }
     Assert.True(number == count);
     session.Commit();
   }
 }
Ejemplo n.º 29
0
        public static HashSet <Person> SearchGeoHashIndex(string bootDirectory, double minLat, double minLon, double maxLat, double maxLon)
        {
            HashSet <Person> resultSet = new HashSet <Person>();

            if (minLat > maxLat)
            {
                double t = minLat;
                minLat = maxLat;
                maxLat = t;
            }
            if (minLon > maxLon)
            {
                double t = minLon;
                minLon = maxLon;
                maxLon = t;
            }
            WGS84Point              min   = new WGS84Point(minLat, minLon);
            WGS84Point              max   = new WGS84Point(maxLat, maxLon);
            BoundingBox             bbox  = new BoundingBox(min, max);
            GeoHashBoundingBoxQuery query = new GeoHashBoundingBoxQuery(bbox);

            using (SessionNoServer session = new SessionNoServer(bootDirectory))
            {
                session.BeginRead();
                BTreeMap <Int64, VelocityDbList <Person> > btreeMap = session.AllObjects <BTreeMap <Int64, VelocityDbList <Person> > >().FirstOrDefault();
                foreach (GeoHash hash in query.SearchHashes)
                {
                    BTreeMapIterator <Int64, VelocityDbList <Person> > itr = btreeMap.Iterator();
                    itr.GoTo(hash.LongValue);
                    var current = itr.Current();
                    while (current.Value != null)
                    {
                        GeoHash geoHash = GeoHash.FromLongValue(current.Key);
                        if (geoHash.Within(hash) || (geoHash.SignificantBits > hash.SignificantBits && hash.Within(geoHash)))
                        {
                            foreach (Person person in current.Value)
                            {
                                resultSet.Add(person);
                            }
                            current = itr.Next();
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                // actual geohash bounding box may be including some that are not within requested bounding box so remove such items if any
                HashSet <Person> notWithin = new HashSet <Person>();
                foreach (Person person in resultSet)
                {
                    if (person.Lattitude < min.Latitude || person.Lattitude > max.Latitude || person.Longitude < min.Longitude || person.Lattitude > max.Latitude)
                    {
                        notWithin.Add(person);
                    }
                }
                foreach (Person person in notWithin)
                {
                    resultSet.Remove(person);
                }
                foreach (Person person in resultSet)
                {
                    Console.WriteLine(person.ToString() + " Lattitude: " + person.Lattitude + " Longitude: " + person.Longitude);
                }
                session.Commit();
            }

            return(resultSet);
        }
Ejemplo n.º 30
0
 public ActingPerson(string name, SessionBase session)
 {
     this.name = name;
     inMovieAs = new BTreeMap <Movie, string>(null, session);
 }
Ejemplo n.º 31
0
        static void Main(string[] args)
        {
            long triangles = 0;

            try
            {
                using (SessionNoServer session = new SessionNoServer(systemDir))
                {
                    int numberOfWorkerThreads = -1;
                    if (args.Length > 0)
                    {
                        if (!int.TryParse(args[0], out numberOfWorkerThreads))
                        {
                            Console.WriteLine("First parameter is numberOfWorkerThreads which must be an Int32");
                        }
                    }
                    bool useLinq = args.Length > 1;
                    session.BeginUpdate();
                    BTreeMapIterator <int, int[]> edgesItr;
                    int[] edge = null;
                    BTreeMap <int, int[]> edges = session.AllObjects <BTreeMap <int, int[]> >(false).FirstOrDefault();
                    if (edges != null)
                    {
                        session.Commit();
                        session.BeginRead();
                    }
                    else
                    {
                        DatabaseLocation location = session.DatabaseLocations.Default();
                        edges = new BTreeMap <int, int[]>(null, session, 6000);
                        session.Persist(edges);
                        edgesItr = edges.Iterator();
                        using (StreamReader stream = new StreamReader(edgesInputFile, true))
                        {
                            int      a;
                            int      b;
                            string   line;
                            string[] fields;
                            while ((line = stream.ReadLine()) != null)
                            {
                                fields = line.Split(' ');
                                if (!int.TryParse(fields[0], out a))
                                {
                                    break;
                                }
                                b = int.Parse(fields[1]);
                                if (a != b)
                                {
                                    if (edgesItr.CurrentKey() == a || edgesItr.GoTo(a))
                                    {
                                        edge = edgesItr.CurrentValue();
                                        Array.Resize(ref edge, edge.Length + 1);
                                        edge[edge.Length - 1] = b;
                                        edgesItr.ReplaceValue(ref edge); // we need to update the value in the BTreeMap
                                    }
                                    else
                                    {
                                        edge    = new int[1];
                                        edge[0] = b;
                                        edges.Add(a, edge);
                                    }
                                }
                            }
                        }
                        edgesItr = edges.Iterator();
                        while (edgesItr.MoveNext())
                        {
                            edge = edgesItr.CurrentValue();
                            Array.Sort(edge);
                            edgesItr.ReplaceValue(ref edge);
                        }
                        session.Commit();
                        session.BeginRead();
                    }
                    Console.WriteLine("Number of Nodes found: " + edges.Count);
                    if (useLinq)
                    {
                        Console.WriteLine("Query using LINQ");
                    }
                    if (numberOfWorkerThreads > 0)
                    {
                        Console.WriteLine("Start of triangle discovery using " + numberOfWorkerThreads + " threads, time is " + DateTime.Now);
                    }
                    else if (numberOfWorkerThreads < 0)
                    {
                        Console.WriteLine("Start of triangle discovery using system automatically selected number of threads, time is " + DateTime.Now);
                    }
                    else
                    {
                        Console.WriteLine("Start of triangle discovery using main thread, time is " + DateTime.Now);
                    }

                    // Start counting triangles !
                    if (numberOfWorkerThreads != 0)
                    {
                        if (useLinq)
                        { // Please help, I have not figured out how to properly do the triangle query using LINQ
                            int[] edge2values = null;
                            if (numberOfWorkerThreads > 0)
                            {
                                triangles = (from KeyValuePair <int, int[]> edgeFrom in edges
                                             from int edgeTo1 in edgeFrom.Value
                                             where edgeFrom.Key < edgeTo1
                                             from int edgeTo2 in edgeFrom.Value
                                             where edgeFrom.Key < edgeTo2 && edgeTo2 > edgeTo1 && edges.TryGetValue(edgeTo1, out edge2values) && Array.BinarySearch(edge2values, edgeTo2) >= 0
                                             select edge).AsParallel().WithDegreeOfParallelism(numberOfWorkerThreads).Count();
                            }
                            else
                            {
                                triangles = (from KeyValuePair <int, int[]> edgeFrom in edges
                                             from int edgeTo1 in edgeFrom.Value
                                             where edgeFrom.Key < edgeTo1
                                             from int edgeTo2 in edgeFrom.Value
                                             where edgeFrom.Key <edgeTo2 && edgeTo2> edgeTo1 && edges.TryGetValue(edgeTo1, out edge2values) && Array.BinarySearch(edge2values, edgeTo2) >= 0
                                             select edge).AsParallel().Count();
                            }
                        }
                        else
                        {
                            edgesItr = edges.Iterator();
                            ParallelOptions pOptions = new ParallelOptions();
                            pOptions.MaxDegreeOfParallelism = numberOfWorkerThreads;
                            // First type parameter is the type of the source elements
                            // Second type parameter is the type of the local data (subtotal)
                            Parallel.ForEach <KeyValuePair <int, int[]>, long>(edges,                    // source collection
                                                                               pOptions,
                                                                               () => 0,                  // method to initialize the local variable
                                                                               (pair, loop, subtotal) => // method invoked by the loop on each iteration
                            {
                                int nodeId   = pair.Key;
                                int[] nodeTo = pair.Value;
                                int stop     = nodeTo.Length - 1;
                                int i        = stop;
                                int edgeToStart, edgeTo;
                                int pos;
                                while (i >= 0)
                                {
                                    int[] edgeInfo2;
                                    edgeToStart = nodeTo[i--];
                                    if (nodeId < edgeToStart)
                                    {
                                        if (edges.TryGetValue(edgeToStart, out edgeInfo2))
                                        {
                                            for (int j = stop; j >= i; j--)
                                            {
                                                edgeTo = nodeTo[j];
                                                if (edgeToStart < edgeTo)
                                                {
                                                    pos = Array.BinarySearch <int>(edgeInfo2, edgeTo);
                                                    if (pos >= 0)
                                                    { // we know this one is connected to edgeInfo.From because it is part of edgeInfo.To
                                                        subtotal++;
                                                    }
                                                }
                                                else
                                                {
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                return(subtotal);
                            },
                                                                               // Method to be executed when all loops have completed.
                                                                               // finalResult is the final value of subtotal. supplied by the ForEach method.
                                                                               (finalResult) => Interlocked.Add(ref triangles, finalResult));
                        }
                    }
                    else if (useLinq)
                    {
                        triangles = queryUsingLINQ(edges);
                    }
                    else
                    {
                        triangles = discoverTrianglesSingleCore(edges);
                    }

                    session.Commit();
                }
                Console.WriteLine("Number of Triangles found: " + triangles + ", time is " + DateTime.Now);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
            }
        }
Ejemplo n.º 32
0
 public BTreeMapOwner()
 {
     _locationByZipCode = new BTreeMap <string, BTreeSet <LocationWithinUSA> >(null, null);
 }
Ejemplo n.º 33
0
    static void Main(string[] args)
    {
      long triangles = 0;
      try
      {
        using (SessionNoServer session = new SessionNoServer(systemDir))
        {
          int numberOfWorkerThreads = -1;
          if (args.Length > 0)
          {
            if (!int.TryParse(args[0], out numberOfWorkerThreads))
              Console.WriteLine("First parameter is numberOfWorkerThreads which must be an Int32");
          }
          bool useLinq = args.Length > 1;
          Placement btreePlace = new Placement(40, 1, 1, 10000, 65500, true);
          Placement edgeInfoPlace = new Placement(40, 10000, 1, 10000, 65500, true);
          session.BeginUpdate();
          BTreeMap<int, int[]> edges;
          BTreeMapIterator<int, int[]> edgesItr;
          int[] edge = null;
          Database edgeDb = session.OpenDatabase(40, false, false);
          if (edgeDb != null)
          {
            session.Commit();
            session.BeginRead();
            edges = (BTreeMap<int, int[]>)session.Open(40, 1, 1, false);
          }
          else
          {
            DatabaseLocation location = session.DatabaseLocations.Default();
            //location.CompressPages = false; // no compression should make it faster (?) 
            session.NewDatabase(40, 395, "Edges");
            edges = new BTreeMap<int, int[]>(null, session, 6000);
            edges.Persist(btreePlace, session, true);
            edgesItr = edges.Iterator();
            using (StreamReader stream = new StreamReader(edgesInputFile, true))
            {
              int a;
              int b;
              string line;
              string[] fields;
              while ((line = stream.ReadLine()) != null)
              {
                fields = line.Split(' ');
                if (!int.TryParse(fields[0], out a))
                  break;
                b = int.Parse(fields[1]);
                if (a != b)
                {
                  if (edgesItr.CurrentKey() == a || edgesItr.GoTo(a))
                  {
                    edge = edgesItr.CurrentValue();
                    Array.Resize(ref edge, edge.Length + 1);
                    edge[edge.Length - 1] = b;
                    edgesItr.ReplaceValue(ref edge); // we need to update the value in the BTreeMap
                  }
                  else
                  {
                    edge = new int[1];
                    edge[0] = b;
                    edges.Add(a, edge);
                  }
                }
              }
            }
            edgesItr = edges.Iterator();
            while (edgesItr.MoveNext())
            {
              edge = edgesItr.CurrentValue();
              Array.Sort(edge);
              edgesItr.ReplaceValue(ref edge);
            }
            session.Commit();
            session.BeginRead();
          }
          Console.WriteLine("Number of Nodes found: " + edges.Count);
          if (useLinq)
            Console.WriteLine("Query using LINQ");
          if (numberOfWorkerThreads > 0)           
            Console.WriteLine("Start of triangle discovery using " + numberOfWorkerThreads + " threads, time is " + DateTime.Now);
          else if (numberOfWorkerThreads < 0)
            Console.WriteLine("Start of triangle discovery using system automatically selected number of threads, time is " + DateTime.Now);
          else
            Console.WriteLine("Start of triangle discovery using main thread, time is " + DateTime.Now);

          // Start counting triangles !
          if (numberOfWorkerThreads != 0)
          {
            if (useLinq)
            { // Please help, I have not figured out how to properly do the triangle query using LINQ
              int[] edge2values = null;
              if (numberOfWorkerThreads > 0)
                triangles = (from KeyValuePair<int, int[]> edgeFrom in edges
                           from int edgeTo1 in edgeFrom.Value
                           where edgeFrom.Key < edgeTo1
                           from int edgeTo2 in edgeFrom.Value
                           where edgeFrom.Key < edgeTo2 && edgeTo2 > edgeTo1 && edges.TryGetValue(edgeTo1, out edge2values) && Array.BinarySearch(edge2values, edgeTo2) >= 0
                           select edge).AsParallel().WithDegreeOfParallelism(numberOfWorkerThreads).Count();
              else
                triangles =  (from KeyValuePair<int, int[]> edgeFrom in edges
                              from int edgeTo1 in edgeFrom.Value
                             where edgeFrom.Key < edgeTo1
                             from int edgeTo2 in edgeFrom.Value
                             where edgeFrom.Key < edgeTo2 && edgeTo2 > edgeTo1 && edges.TryGetValue(edgeTo1, out edge2values) && Array.BinarySearch(edge2values, edgeTo2) >= 0
                             select edge).AsParallel().Count();
            }
            else
            {
              edgesItr = edges.Iterator();
              ParallelOptions pOptions = new ParallelOptions();
              pOptions.MaxDegreeOfParallelism = numberOfWorkerThreads;
              // First type parameter is the type of the source elements
              // Second type parameter is the type of the local data (subtotal)
              Parallel.ForEach<KeyValuePair<int, int[]>, long>(edges, // source collection
                pOptions,
                () => 0, // method to initialize the local variable
                (pair, loop, subtotal) => // method invoked by the loop on each iteration
                {
                  int nodeId = pair.Key;
                  int[] nodeTo = pair.Value;
                  int stop = nodeTo.Length - 1;
                  int i = stop;
                  int edgeToStart, edgeTo;
                  int pos;
                  while (i >= 0)
                  {
                    int[] edgeInfo2;
                    edgeToStart = nodeTo[i--];
                    if (nodeId < edgeToStart)
                    {
                      if (edges.TryGetValue(edgeToStart, out edgeInfo2))
                      {
                        for (int j = stop; j >= i; j--)
                        {
                          edgeTo = nodeTo[j];
                          if (edgeToStart < edgeTo)
                          {
                            pos = Array.BinarySearch<int>(edgeInfo2, edgeTo);
                            if (pos >= 0)
                            { // we know this one is connected to edgeInfo.From because it is part of edgeInfo.To
                              subtotal++;
                            }
                          }
                          else
                            break;
                        }
                      }
                    }
                    else
                      break;
                  }
                  return subtotal;
                },
                // Method to be executed when all loops have completed.
                // finalResult is the final value of subtotal. supplied by the ForEach method.
                (finalResult) => Interlocked.Add(ref triangles, finalResult));
            }
          }
          else if (useLinq)
            triangles = queryUsingLINQ(edges);
          else
            triangles = discoverTrianglesSingleCore(edges);

          session.Commit();

        }
        Console.WriteLine("Number of Triangles found: " + triangles);
      }
      catch (Exception e)
      {
        System.Console.WriteLine(e);
      }
    }