Exemple #1
0
        public IEdge AddEdge(object id, IVertex outVertex, IVertex inVertex, string label)
        {
            GraphContract.ValidateAddEdge(id, outVertex, inVertex, label);
            if (_uniqueIds && null != id && null != GetEdge(id))
            {
                throw new ArgumentException(string.Concat("edge with given id already exists: ", id));
            }

            VerifyNativeElement(outVertex);
            VerifyNativeElement(inVertex);

            var base_ = _baseGraph.AddEdge(id, ((IdVertex)outVertex).GetBaseVertex(),
                                           ((IdVertex)inVertex).GetBaseVertex(), label);

            if (_supportEdgeIds)
            {
                var v = id ?? _edgeIdFactory.CreateId();

                if (null != v)
                {
                    base_.SetProperty(Id, v);
                }
            }

            return(new IdEdge(base_, this));
        }
Exemple #2
0
 public virtual IEnumerable <IVertex> GetVertices(string key, object value)
 {
     GraphContract.ValidateGetVertices(key, value);
     return(VertexKeyIndex.GetIndexedKeys().Contains(key)
                ? VertexKeyIndex.Get(key, value).Cast <IVertex>()
                : new PropertyFilteredIterable <IVertex>(key, value, GetVertices()));
 }
Exemple #3
0
        public IVertex GetVertex(object id)
        {
            GraphContract.ValidateGetVertex(id);
            var vertex = BaseGraph.GetVertex(id);

            return(null == vertex ? null : new EventVertex(vertex, this));
        }
Exemple #4
0
        public IEdge AddEdge(object id, IVertex outVertex, IVertex inVertex, string label)
        {
            GraphContract.ValidateAddEdge(id, outVertex, inVertex, label);

            if (!(outVertex is BatchVertex) || !(inVertex is BatchVertex))
            {
                throw new ArgumentException("Given element was not created in this baseGraph");
            }
            NextElement();

            var ov = GetCachedVertex(outVertex.Id);
            var iv = GetCachedVertex(inVertex.Id);

            _previousOutVertexId = outVertex.Id; //keep track of the previous out vertex id

            if (ov != null && iv != null)
            {
                _currentEdgeCached = _baseGraph.AddEdge(id, ov, iv, label);
                if (_edgeIdKey != null && id != null)
                {
                    _currentEdgeCached.SetProperty(_edgeIdKey, id);
                }
            }

            _currentEdge = new BatchEdge(this);
            return(_currentEdge);
        }
Exemple #5
0
        public virtual IVertex GetVertex(object id)
        {
            GraphContract.ValidateGetVertex(id);
            var idString = id.ToString();

            return(InnerVertices.Get(idString));
        }
Exemple #6
0
        /// <note>
        ///     Raises an edgeAdded event.
        /// </note>
        public IEdge AddEdge(object id, IVertex outVertex, IVertex inVertex, string label)
        {
            GraphContract.ValidateAddEdge(id, outVertex, inVertex, label);
            var outVertexToSet = outVertex;

            if (outVertex is EventVertex)
            {
                outVertexToSet = (outVertex as EventVertex).Vertex;
            }

            var inVertexToSet = inVertex;

            if (inVertex is EventVertex)
            {
                inVertexToSet = (inVertex as EventVertex).Vertex;
            }

            if (inVertexToSet == null || outVertexToSet == null)
            {
                throw new InvalidOperationException();
            }
            var edge = BaseGraph.AddEdge(id, outVertexToSet, inVertexToSet, label);

            OnEdgeAdded(edge);
            return(new EventEdge(edge, this));
        }
Exemple #7
0
        public IVertex GetVertex(object id)
        {
            GraphContract.ValidateGetVertex(id);
            if (null == id)
            {
                throw new ArgumentNullException("id");
            }

            if (_supportVertexIds)
            {
                var i    = _baseGraph.GetVertices(Id, id);
                var iter = i.GetEnumerator();
                if (!iter.MoveNext())
                {
                    return(null);
                }
                var e = iter.Current;

                if (iter.MoveNext())
                {
                    throw new InvalidOperationException(string.Concat("multiple vertices exist with id '", id, "'"));
                }

                return(new IdVertex(e, this));
            }
            var base_ = _baseGraph.GetVertex(id);

            return(null == base_ ? null : new IdVertex(base_, this));
        }
Exemple #8
0
        public virtual IEdge GetEdge(object id)
        {
            GraphContract.ValidateGetEdge(id);
            var idString = id.ToString();

            return(Edges.Get(idString));
        }
Exemple #9
0
        public virtual void RemoveEdge(IEdge edge)
        {
            GraphContract.ValidateRemoveEdge(edge);

            var   outVertex = (TinkerVertex)edge.GetVertex(Direction.Out);
            var   inVertex  = (TinkerVertex)edge.GetVertex(Direction.In);
            IEdge removedEdge;

            if (null != outVertex && null != outVertex.OutEdges)
            {
                var e = outVertex.OutEdges.Get(edge.Label);
                if (null != e)
                {
                    e.TryRemove(edge.Id.ToString(), out removedEdge);
                }
            }
            if (null != inVertex && null != inVertex.InEdges)
            {
                var e = inVertex.InEdges.Get(edge.Label);
                if (null != e)
                {
                    e.TryRemove(edge.Id.ToString(), out removedEdge);
                }
            }


            EdgeKeyIndex.RemoveElement(edge);
            foreach (var idx in GetIndices().Where(t => t.Type == typeof(IEdge)).Cast <TinkerIndex>())
            {
                idx.RemoveElement(edge);
            }

            Edges.TryRemove(edge.Id.ToString(), out removedEdge);
        }
        public IVertex GetVertex(object id)
        {
            GraphContract.ValidateGetVertex(id);
            var vertex = BaseGraph.GetVertex(id);

            return(null == vertex ? null : new ReadOnlyVertex(this, vertex));
        }
        public void MergeVertex(TVertex v, EdgeFactory <TVertex, TEdge> edgeFactory)
        {
            Contract.Requires(GraphContract.InVertexSet(this, v));
            Contract.Requires(edgeFactory != null);

            // storing edges in local array
            var inedges  = this.vertexInEdges[v];
            var outedges = this.vertexOutEdges[v];

            // remove vertex
            this.RemoveVertex(v);

            // add edges from each source to each target
            foreach (var source in inedges)
            {
                //is it a self edge
                if (source.Source.Equals(v))
                {
                    continue;
                }
                foreach (var target in outedges)
                {
                    if (v.Equals(target.Target))
                    {
                        continue;
                    }
                    // we add an new edge
                    this.AddEdge(edgeFactory(source.Source, target.Target));
                }
            }
        }
Exemple #12
0
 public virtual IEnumerable <IEdge> GetEdges(string key, object value)
 {
     GraphContract.ValidateGetEdges(key, value);
     if (EdgeKeyIndex.GetIndexedKeys().Contains(key))
     {
         return(EdgeKeyIndex.Get(key, value).Cast <IEdge>());
     }
     return(new PropertyFilteredIterable <IEdge>(key, value, GetEdges()));
 }
Exemple #13
0
 public IEnumerable <IVertex> GetVertices(string key, object value)
 {
     GraphContract.ValidateGetVertices(key, value);
     if (_supportVertexIds && key == Id)
     {
         throw new ArgumentException(string.Concat("index key ", Id, " is reserved by idInnerTinkerGrapĥ"));
     }
     return(new IdVertexIterable(_baseGraph.GetVertices(key, value), this));
 }
Exemple #14
0
        public IVertex GetVertex(object id)
        {
            GraphContract.ValidateGetVertex(id);
            IVertex vertex = BaseGraph.GetVertex(id);

            if (null == vertex || !IsInPartition(vertex))
            {
                return(null);
            }

            return(new PartitionVertex(vertex, this));
        }
Exemple #15
0
        public IEdge AddEdge(object id, IVertex outVertex, IVertex inVertex, string label)
        {
            GraphContract.ValidateAddEdge(id, outVertex, inVertex, label);

            var edge = new PartitionEdge(BaseGraph.AddEdge(id,
                                                           ((PartitionVertex)outVertex).Vertex,
                                                           ((PartitionVertex)inVertex).Vertex,
                                                           label),
                                         this);

            edge.SetPartition(_writePartition);
            return(edge);
        }
 private static void AssertGraphsEqual(
     IEdgeListGraph <int, Edge <int> > g,
     IEdgeListGraph <int, Edge <int> > result)
 {
     // check equal
     Assert.IsTrue(GraphContract.VertexCountEqual(g, result));
     Assert.IsTrue(GraphContract.EdgeCountEqual(g, result));
     foreach (var v in g.Vertices)
     {
         Assert.IsTrue(result.ContainsVertex(v));
     }
     //foreach (var e in g.Edges)
     //    Assert.IsTrue(result.ContainsEdge(e.Source, e.Target));
 }
Exemple #17
0
        /// <note>
        ///     Raises a vertexRemoved event.
        /// </note>
        public void RemoveVertex(IVertex vertex)
        {
            GraphContract.ValidateRemoveVertex(vertex);
            var vertexToRemove = vertex;

            if (vertex is EventVertex)
            {
                vertexToRemove = (vertex as EventVertex).Vertex;
            }

            var props = vertex.GetProperties();

            if (vertexToRemove != null)
            {
                BaseGraph.RemoveVertex(vertexToRemove);
                OnVertexRemoved(vertex, props);
            }
        }
Exemple #18
0
        public virtual void RemoveVertex(IVertex vertex)
        {
            GraphContract.ValidateRemoveVertex(vertex);

            foreach (var edge in vertex.GetEdges(Direction.Both))
            {
                RemoveEdge(edge);
            }

            VertexKeyIndex.RemoveElement(vertex);
            foreach (var idx in GetIndices().Where(t => t.Type == typeof(IVertex)).Cast <TinkerIndex>())
            {
                idx.RemoveElement(vertex);
            }

            IVertex removedVertex;

            InnerVertices.TryRemove(vertex.Id.ToString(), out removedVertex);
        }
Exemple #19
0
        /// <note>
        ///     If the input data are sorted, then out vertex will be repeated for several edges in a row.
        ///     In this case, bypass cache and instead immediately return a new vertex using the known id.
        ///     This gives a modest performance boost, especially when the cache is large or there are
        ///     on average many edges per vertex.
        /// </note>
        public IVertex GetVertex(object id)
        {
            GraphContract.ValidateGetVertex(id);
            if ((_previousOutVertexId != null) && (_previousOutVertexId == id))
            {
                return(new BatchVertex(_previousOutVertexId, this));
            }
            var v = RetrieveFromCache(id);

            if (v == null)
            {
                if (_loadingFromScratch)
                {
                    return(null);
                }
                if (_baseGraph.Features.IgnoresSuppliedIds)
                {
                    Debug.Assert(_vertexIdKey != null);
                    var iter = _baseGraph.GetVertices(_vertexIdKey, id).GetEnumerator();
                    if (!iter.MoveNext())
                    {
                        return(null);
                    }
                    v = iter.Current;
                    if (iter.MoveNext())
                    {
                        throw new ArgumentException(
                                  string.Concat("There are multiple vertices with the provided id in the database: ", id));
                    }
                }
                else
                {
                    v = _baseGraph.GetVertex(id);
                    if (v == null)
                    {
                        return(null);
                    }
                }
                _cache.Set(v, id);
            }
            return(new BatchVertex(id, this));
        }
Exemple #20
0
        public virtual IEdge AddEdge(object id, IVertex outVertex, IVertex inVertex, string label)
        {
            GraphContract.ValidateAddEdge(id, outVertex, inVertex, label);

            string idString = null;
            IEdge  edge;

            if (null != id)
            {
                idString = id.ToString();
                edge     = Edges.Get(idString);
                if (null != edge)
                {
                    throw ExceptionFactory.EdgeWithIdAlreadyExist(id);
                }
            }
            else
            {
                var done = false;
                while (!done)
                {
                    idString = GetNextId();
                    edge     = Edges.Get(idString);
                    if (null == edge)
                    {
                        done = true;
                    }
                }
            }

            edge = new TinkerEdge(idString, outVertex, inVertex, label, this);
            Edges.Put(edge.Id.ToString(), edge);
            var out_ = (TinkerVertex)outVertex;
            var in_  = (TinkerVertex)inVertex;

            out_.AddOutEdge(label, edge);
            in_.AddInEdge(label, edge);
            return(edge);
        }
Exemple #21
0
        public IEdge AddEdge(object id, IVertex outVertex, IVertex inVertex, string label)
        {
            GraphContract.ValidateAddEdge(id, outVertex, inVertex, label);

            return(_graph.AddEdge(id, outVertex, inVertex, label));
        }
Exemple #22
0
 public IEnumerable <IVertex> GetVertices(string key, object value)
 {
     GraphContract.ValidateGetVertices(key, value);
     return(_graph.GetVertices(key, value));
 }
Exemple #23
0
 public void RemoveVertex(IVertex vertex)
 {
     GraphContract.ValidateRemoveVertex(vertex);
     _graph.RemoveVertex(vertex);
 }
Exemple #24
0
 public IVertex GetVertex(object id)
 {
     GraphContract.ValidateGetVertex(id);
     return(_graph.GetVertex(id));
 }
Exemple #25
0
 public IEnumerable <IVertex> GetVertices(string key, object value)
 {
     GraphContract.ValidateGetVertices(key, value);
     throw RetrievalNotSupported();
 }
 public void RemoveVertex(IVertex vertex)
 {
     GraphContract.ValidateRemoveVertex(vertex);
     throw new InvalidOperationException(ReadOnlyTokens.MutateErrorMessage);
 }
 public IEnumerable <IVertex> GetVertices(string key, object value)
 {
     GraphContract.ValidateGetVertices(key, value);
     return(new ReadOnlyVertexIterable(this, BaseGraph.GetVertices(key, value)));
 }
Exemple #28
0
 public void RemoveVertex(IVertex vertex)
 {
     GraphContract.ValidateRemoveVertex(vertex);
     VerifyNativeElement(vertex);
     _baseGraph.RemoveVertex(((IdVertex)vertex).GetBaseVertex());
 }
Exemple #29
0
 public void RemoveVertex(IVertex vertex)
 {
     GraphContract.ValidateRemoveVertex(vertex);
     BaseGraph.RemoveVertex(((PartitionVertex)vertex).Vertex);
 }
Exemple #30
0
 public IEnumerable <IVertex> GetVertices(string key, object value)
 {
     GraphContract.ValidateGetVertices(key, value);
     return(new EventVertexIterable(BaseGraph.GetVertices(key, value), this));
 }