Example #1
0
        /// <summary>
        /// Creates a new Property.
        /// </summary>
        /// <param name="name">Unique name for the new Property.</param>
        /// <param name="dt">Data type for the new Property.</param>
        /// <param name="kind">Property kind.</param>
        /// <returns>a Property.</returns>
        public PropertyType NewProperty(string name, DataType dt, PropertyKind kind)
        {
            PropertyType aType;

            if (stringToPropertyType.TryGetValue(name, out aType) == false)
            {
                graph.Update();
                int pos = -1;
                int i   = 0;
                foreach (PropertyType pt in graph.propertyType)
                {
                    if (pt == null)
                    {
                        pos = i;
                        break;
                    }
                    else
                    {
                        ++i;
                    }
                }
                if (pos < 0)
                {
                    pos = graph.propertyType.Length;
                    Array.Resize(ref graph.propertyType, pos + 1);
                }
                aType = graph.PropertyTypeFromDataType(false, dt, this.TypeId, pos, name, kind);
                graph.propertyType[pos] = aType;
                stringToPropertyType.AddFast(name, aType);
            }
            return(aType);
        }
Example #2
0
        /// <summary>
        /// Creates a new Property.
        /// </summary>
        /// <param name="name">Unique name for the new Property.</param>
        /// <param name="dt">Data type for the new Property.</param>
        /// <param name="kind">Property kind.</param>
        /// <returns>a Property.</returns>
        public PropertyType NewProperty(string name, DataType dt, PropertyKind kind)
        {
            PropertyType aType;

            if (m_stringToPropertyType.TryGetValue(name, out aType) == false)
            {
                var propertyTypes = MyGraph.PropertyTypes;
                int pos           = -1;
                int i             = 0;
                foreach (PropertyType pt in propertyTypes)
                {
                    if (pt == null)
                    {
                        pos = i;
                        break;
                    }
                    else
                    {
                        ++i;
                    }
                }
                if (pos < 0)
                {
                    pos = propertyTypes.Count;
                }
                aType = MyGraph.PropertyTypeFromDataType(false, dt, this.TypeId, pos, name, kind);
                Session.Persist(aType);
                propertyTypes[pos] = aType;
                m_stringToPropertyType.AddFast(name, aType);
            }
            return(aType);
        }
Example #3
0
 /// <summary>
 /// Internally gets a property value
 /// </summary>
 /// <param name="oid">element id</param>
 /// <param name="pv">a value</param>
 /// <returns></returns>
 protected bool GetPropertyValueT(ElementId oid, ref T pv)
 {
     if (m_propertyValue.TryGetValue(oid, out pv))
     {
         return(true);
     }
     return(false);
 }
Example #4
0
        public void ReduceGlobalCount(UInt32 id, UInt32 countReduce)
        {
            UInt32 count;

            if (!_idToGlobalCount.TryGetValue(id, out count))
            {
                _idToGlobalCount[id] = countReduce;
            }
            else
            {
                _idToGlobalCount[id] = count - countReduce;
            }
        }
Example #5
0
        /// <summary>
        /// Creates a new edge type.
        /// </summary>
        /// <param name="name">Unique name for the new edge type.</param>
        /// <param name="biderectional">If true, this creates a biderectional edge type, otherwise this creates a unidirectional edge type.</param>
        /// <param name="baseType">Base EdgeType for the new EdgeType.</param>
        /// <returns>Unique edge type.</returns>
        /// <returns>a new edge type</returns>
        public EdgeType NewEdgeType(string name, bool biderectional, EdgeType baseType = null)
        {
            EdgeType aType;

            if (stringToEdgeType.TryGetValue(name, out aType) == false)
            {
                int pos = edgeTypeCt;
                Update();
                Array.Resize(ref edgeType, ++edgeTypeCt);
                aType         = new EdgeType(pos, name, null, null, biderectional, baseType, this);
                edgeType[pos] = aType;
                stringToEdgeType.AddFast(name, aType);
            }
            return(aType);
        }
Example #6
0
        /// <summary>
        /// Creates a new node type.
        /// </summary>
        /// <param name="name">Unique name for the new vertex type.</param>
        /// <param name="baseType">Base VertexType for the new VertexType.</param>
        /// <returns>Unique graph type identifier.</returns>
        public VertexType NewVertexType(string name, VertexType baseType = null)
        {
            VertexType aType;

            if (stringToVertexType.TryGetValue(name, out aType) == false)
            {
                int pos = vertexTypeCt;
                Update();
                Array.Resize(ref vertexType, (int)++vertexTypeCt);
                aType           = new VertexType(pos, name, baseType, this);
                vertexType[pos] = aType;
                stringToVertexType.AddFast(name, aType);
            }
            return(aType);
        }
Example #7
0
        public Vertex GetVertex(VertexId id)
        {
            if (VertexIdSetPerType)
            {
                throw new NotSupportedException("GetVertex by VertexId on graph level is not supported when using VertexIdSetPerType");
            }
            VertexTypeId tId;

            if (vertexIdToVertexType.TryGetValue(id, out tId))
            {
                VertexType vt = vertexType[tId];
                return(vt.GetVertex(id, false));
            }
            throw new VertexDoesNotExistException();
        }
Example #8
0
        /// <summary>
        /// Gets an edge given an edge id. Throws if no such edge exist.
        /// </summary>
        /// <param name="edgeId">The id of the edge</param>
        /// <returns>The edge with matching id if it exists</returns>
        public Edge GetEdge(EdgeId edgeId)
        {
            if (Unrestricted)
            {
                UnrestrictedEdge headTail;
                if (m_unrestrictedEdges.TryGetValue(edgeId, out headTail))
                {
                    VertexType vt   = headTail.m_headVertexType;
                    Vertex     head = vt.GetVertex(headTail.m_headVertexId);
                    vt = headTail.m_tailVertexType;
                    Vertex tail = vt.GetVertex(headTail.m_tailVertexId);
                    return(new Edge(MyGraph, this, edgeId, head, tail));
                }
            }
            else
            {
                UInt64 vertexVertex;
                if (m_restrictedEdges.TryGetValue(edgeId, out vertexVertex))
                {
                    VertexId headId = (VertexId)(vertexVertex >> 32);
                    Vertex   head   = HeadType.GetVertex(headId);
                    Vertex   tail   = TailType.GetVertex((VertexId)vertexVertex);
                    return(new Edge(MyGraph, this, edgeId, head, tail));
                }
            }

            throw new EdgeDoesNotExistException();
        }
Example #9
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();
   }
 }
Example #10
0
        /// <summary>
        /// Try to find a <see cref="Vertex"/> with a given property value.
        /// </summary>
        /// <param name="value">The property value to look for</param>
        /// <param name="polymorphic">If true, also look for property value matching vertices of property <see cref="VertexType"/> sub classes</param>
        /// <param name="errorIfNotFound">If true, signal an error if no matching <see cref="Vertex"/> found</param>
        /// <returns>A matching Vertex</returns>
        public Vertex GetPropertyVertex(T value, bool polymorphic = false, bool errorIfNotFound = true)
        {
            VertexId elementId = -1;

            if (m_valueIndexUnique == null || m_valueIndexUnique.TryGetValue(value, out elementId) == false)
            {
                BTreeSet <ElementId> elementIds;
                if (m_valueIndex != null && m_valueIndex.TryGetValue(value, out elementIds))
                {
                    elementId = elementIds.First();
                }
            }
            if (elementId == -1)
            {
                return(null);
            }
            VertexType vertexType = MyGraph.VertexTypes[TypeId];

            return(vertexType.GetVertex(elementId, polymorphic, errorIfNotFound));
        }
Example #11
0
        public Vertex GetPropertyVertex(T value, Graph g, bool errorIfNotFound = true)
        {
            VertexId elementId = -1;

            if (valueIndexUnique == null || valueIndexUnique.TryGetValue(value, out elementId) == false)
            {
                BTreeSet <ElementId> elementIds;
                if (valueIndex != null && valueIndex.TryGetValue(value, out elementIds))
                {
                    elementId = elementIds.First();
                }
            }
            if (elementId == -1)
            {
                return(null);
            }
            VertexType vertexType = g.vertexType[TypeId];

            return(vertexType.GetVertex(elementId, false, errorIfNotFound));
        }
Example #12
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);
        }
Example #13
0
        public void RemoveToken(UInt32 id)
        {
            T token;

            if (_IdToValue.TryGetValue(id, out token))
            {
                _IdToValue.Remove(id);
                _valueToId.Remove(token);
                var v = _tokenMap[id];
                v.Unpersist(Session);
                _tokenMap.Remove(id);
            }
        }
Example #14
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);
        }
        /// <summary>
        /// Internally sets a property value
        /// </summary>
        /// <param name="element">element id</param>
        /// <param name="aValue">value</param>
        void SetPropertyValueX(ElementId element, T aValue)
        {
            UInt64 id;

            if (!m_valueToId.TryGetValue(aValue, out id))
            {
                Update();
                id = m_nextId++;
                m_IdToValue[id]     = aValue;
                m_valueToId[aValue] = id;
            }
            base.SetPropertyValueX(element, id);
        }
 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;
 }
Example #17
0
 /// <summary>
 /// Gets an edge given an edge id. Throws if no such edge exist.
 /// </summary>
 /// <param name="edgeId">The id of the edge</param>
 /// <param name="polymorphic">If true and id isn't found in this EdgeType continue search into sub types</param>
 /// <param name="errorIfNotFound">Indicate what to do if <see cref="Edge"/> does not exist</param>
 /// <returns>The edge with matching id if it exists</returns>
 public Edge GetEdge(EdgeId edgeId, bool polymorphic = false, bool errorIfNotFound = true)
 {
     if (Unrestricted)
     {
         UnrestrictedEdge headTail;
         if (m_unrestrictedEdges.TryGetValue(edgeId, out headTail))
         {
             VertexType vt   = headTail.m_headVertexType;
             Vertex     head = vt.GetVertex(headTail.m_headVertexId);
             vt = headTail.m_tailVertexType;
             Vertex tail = vt.GetVertex(headTail.m_tailVertexId);
             return(new Edge(MyGraph, this, edgeId, head, tail));
         }
     }
     else
     {
         UInt64 vertexVertex;
         if (m_restrictedEdges.TryGetValue(edgeId, out vertexVertex))
         {
             VertexId headId = (VertexId)(vertexVertex >> 32);
             Vertex   head   = HeadType.GetVertex(headId);
             Vertex   tail   = TailType.GetVertex((VertexId)vertexVertex);
             return(new Edge(MyGraph, this, edgeId, head, tail));
         }
     }
     if (polymorphic)
     {
         foreach (var et in m_subTypes)
         {
             var e = et.GetEdge(edgeId, polymorphic, false);
             if (e != null)
             {
                 return(e);
             }
         }
     }
     if (errorIfNotFound)
     {
         throw new EdgeDoesNotExistException();
     }
     return(null);
 }
Example #18
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();
     }
 }
Example #19
0
        /// <summary>
        /// Creates a new Property.
        /// </summary>
        /// <param name="name">Unique name for the new Property.</param>
        /// <param name="dt">Data type for the new Property.</param>
        /// <param name="kind">Property kind.</param>
        /// <returns>a Property.</returns>
        public PropertyType NewProperty(string name, DataType dt, PropertyKind kind)
        {
            PropertyType aType;

            if (stringToPropertyType.TryGetValue(name, out aType) == false)
            {
                graph.Update();
                int pos = -1;
                int i   = 0;
                foreach (PropertyType pt in graph.propertyType)
                {
                    if (pt == null)
                    {
                        pos = i;
                        break;
                    }
                    else
                    {
                        ++i;
                    }
                }
                if (pos < 0)
                {
                    pos = graph.propertyType.Length;
                    Array.Resize(ref graph.propertyType, pos + 1);
                }
                switch (dt)
                {
                case DataType.Boolean:
                    aType = new PropertyTypeT <bool>(false, this.TypeId, pos, name, kind, graph);
                    break;

                case DataType.Integer:
                    aType = new PropertyTypeT <int>(false, this.TypeId, pos, name, kind, graph);
                    break;

                case DataType.Long:
                    aType = new PropertyTypeT <long>(false, this.TypeId, pos, name, kind, graph);
                    break;

                case DataType.Double:
                    aType = new PropertyTypeT <double>(false, this.TypeId, pos, name, kind, graph);
                    break;

                case DataType.DateTime:
                    aType = new PropertyTypeT <DateTime>(false, this.TypeId, pos, name, kind, graph);
                    break;

                case DataType.String:
                    aType = new PropertyTypeT <string>(false, this.TypeId, pos, name, kind, graph);
                    break;

                case DataType.Object:
                    aType = new PropertyTypeT <IComparable>(false, this.TypeId, pos, name, kind, graph);
                    break;
                }
                graph.propertyType[pos] = aType;
                stringToPropertyType.AddFast(name, aType);
            }
            return(aType);
        }
    // 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;
    }