示例#1
0
        public int addRelationship(string type, string label1, string from, string label2, string to, Dictionary<string, object> properties)
        {
            int node1 = GetNodeKeyId(label1, from);
            int node2 = GetNodeKeyId(label2, to);
            if (node1 == -1 || node2 == -1) { return -1; }

            related.AddIfAbsent(type, new ReversibleMultiMap());
            relationshipCounts.AddIfAbsent(type, 0);
            relationshipCounts.Add(type, relationshipCounts.getInt(type) + 1);

            int id = relationships.size();
            properties.Add("~incoming_node_id", node1);
            properties.Add("~outgoing_node_id", node2);
            properties.Add("~type", type);
            properties.Add("~id", id);

            relatedCounts.AddIfAbsent(type, new Long2IntOpenHashMap());
            Long2IntOpenHashMap relatedCount = relatedCounts.get(type);
            long countId = ((long)node1 << 32) + node2;
            int count = relatedCount.get(countId) + 1;
            // If this is the second or greater relationship of this type between these two nodes, add it to the properties, else assume it is one.
            if (count > 1)
            {
                properties.Add("~count", count);
            }

            relationships.Add(properties);
            relatedCount.Add(countId, count);
            related.get(type).Add(node1, node2, id);
            addRelationshipKeyId(type, count, node1, node2, id);

            return id;
        }
示例#2
0
        // Relationships
        public int AddRelationship(string type, string label1, string from, string label2, string to)
        {
            int node1 = GetNodeKeyId(label1, from);
            int node2 = GetNodeKeyId(label2, to);
            if (node1 == -1 || node2 == -1) { return -1; }

            related.AddIfAbsent(type, new ReversibleMultiMap());
            relationshipCounts.AddIfAbsent(type, 0);
            relationshipCounts.Add(type, relationshipCounts.getInt(type) + 1);

            relatedCounts.AddIfAbsent(type, new Long2IntOpenHashMap());
            Long2IntOpenHashMap relatedCount = relatedCounts.get(type);
            long countId = ((long)node1 << 32) + node2;
            int count = relatedCount.get(countId) + 1;
            int id = relationships.size();
            Dictionary<string, object> properties = new Dictionary<string, object>();
            properties.Add("~incoming_node_id", node1);
            properties.Add("~outgoing_node_id", node2);
            properties.Add("~type", type);
            properties.Add("~id", id);

            relationships.Add(properties);
            relatedCount.Add(countId, count);
            related.get(type).Add(node1, node2, id);
            addRelationshipKeyId(type, count, node1, node2, id);

            return id;
        }
示例#3
0
        private void addRelationshipKeyId(string type, int count, int node1, int node2, int id)
        {

            if (!relationshipKeys.ContainsKey(type + count))
            {
                Long2IntOpenHashMap relKey = new Long2IntOpenHashMap();
                relKey.defaultReturnValue(-1);
                relKey.Add(((long)node1 << 32) + node2, id);
                relationshipKeys.Add(type + count, relKey);
            }
            else
            {
                relationshipKeys.get(type + count).Add(((long)node1 << 32) + node2, id);
            }

        }