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 (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 #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 (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 #3
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 #4
0
 /// <summary>
 /// Internally sets a property value
 /// </summary>
 /// <param name="element">element id</param>
 /// <param name="aValue">value</param>
 virtual protected void SetPropertyValueX(ElementId element, T aValue)
 {
     Update();
     m_propertyValue[element] = aValue;
     if (m_valueIndex != null)
     {
         BTreeSet <ElementId> oidArray;
         if (!m_valueIndex.TryGetKey(aValue, ref aValue))
         {
             oidArray = new BTreeSet <ElementId>(null, Session);
             oidArray.Add(element);
             m_valueIndex.AddFast(aValue, oidArray);
         }
         else
         {
             oidArray = m_valueIndex[aValue];
             oidArray.Add(element);
             m_valueIndex[aValue] = oidArray;
         }
     }
     else if (m_valueIndexUnique != null)
     {
         m_valueIndexUnique.AddFast(aValue, element);
     }
 }
Example #5
0
 void SetPropertyValueX(ElementId element, T aValue)
 {
     Update();
     propertyValue[element] = aValue;
     if (valueIndex != null)
     {
         BTreeSet <ElementId> oidArray;
         if (!valueIndex.TryGetKey(aValue, ref aValue))
         {
             oidArray = new BTreeSet <ElementId>(null, graph.Session);
             oidArray.Add(element);
             valueIndex.AddFast(aValue, oidArray);
         }
         else
         {
             oidArray = valueIndex[aValue];
             oidArray.Add(element);
             valueIndex[aValue] = oidArray;
         }
     }
     else if (valueIndexUnique != null)
     {
         valueIndexUnique.AddFast(aValue, element);
     }
 }
Example #6
0
        public UInt32 PossiblyAddToken(T token, Document doc)
        {
            UInt32 id;
            BTreeSet <Document> docSet;

            if (!ValueToId.TryGetValue(token, out id))
            {
                Update();
                id = ++_nextId;
                _IdToValue.AddFast(id, token);
                _valueToId.Add(token, id);
                docSet = new BTreeSet <Document>();
                _tokenMap.AddFast(id, docSet);
            }
            else
            {
                docSet = _tokenMap[id];
            }
            UInt32 wordHit;

            if (!doc.WordHit.TryGetValue(id, out wordHit))
            {
                docSet.AddFast(doc);
                doc.WordHit.Add(id, 1);
            }
            else
            {
                doc.WordHit[id] = ++wordHit;
            }
            AddToGlobalCount(id, 1);
            return(id);
        }
Example #7
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 #8
0
        /// <summary>
        /// Create an edge between tail and head vertex
        /// </summary>
        /// <param name="tail">selected tail vertex</param>
        /// <param name="head">selected head vertex</param>
        /// <returns>a new edge</returns>
        public Edge NewEdge(Vertex tail, Vertex head)
        {
            if (m_tailType != null && tail.VertexType != TailType)
            {
                throw new InvalidTailVertexTypeException();
            }
            if (m_headType != null && head.VertexType != HeadType)
            {
                throw new InvalidHeadVertexTypeException();
            }
            EdgeId eId = NewEdgeId(MyGraph);

            if (Unrestricted)
            {
                m_unrestrictedEdges.AddFast(eId, new UnrestrictedEdge {
                    m_headVertexType = head.VertexType, m_headVertexId = head.VertexId, m_tailVertexType = tail.VertexType, m_tailVertexId = tail.VertexId
                });
            }
            else
            {
                UInt64 vertexVertex = (UInt64)head.VertexId;
                vertexVertex  = vertexVertex << 32;
                vertexVertex += (UInt64)tail.VertexId;
                m_restrictedEdges.AddFast(eId, vertexVertex);
            }
            Edge edge = new Edge(MyGraph, this, eId, head, tail);

            if (m_birectional)
            {
                tail.VertexType.NewTailToHeadEdge(this, edge, tail, head, Session);
                head.VertexType.NewHeadToTailEdge(this, edge, tail, head, Session);
            }
            else
            {
                tail.VertexType.NewTailToHeadEdge(this, edge, tail, head, Session);
            }
            return(edge);
        }
Example #9
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);
        }
Example #10
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));
   }
 }
Example #11
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));
   }
 }