Beispiel #1
0
//AddEdge
func (n *Node) AddEdge(tarNodeIndex *engine.ObjectIndex) (*edge.Edge, bool) {
	if n.OutDegree > 0 {
		for _, e := range n.OutEdges {
			if e.Target.Equals(tarNodeIndex) {
				// println("Node.AddEdge.False")
				return e, false
			}
		}
	}
	e := edge.New(n.Index, tarNodeIndex)
	println(n.Index.String(), tarNodeIndex.String())
	n.OutEdges = append(n.OutEdges, e)
	n.OutDegree++
	return e, true
}
Beispiel #2
0
// Returns the find result & value to which the specified key is mapped,
// or nil if this map contains no mapping for the key.
//
// More formally, if this map contains a mapping from a key
// to a value such that (key==null ? k==null :
// key.equals(k)), then this method returns v; otherwise
// it returns nil.  (There can be at most one such mapping.)
func (c Collection) Get(key *engine.ObjectIndex) (*node.Node, bool) {
	//if key == nil {
	//	return c.getForNullKey()
	//}
	h := hash(key.GetId())
	es := c.table[indexFor(h, c.capacity)]
	if es == nil {
		return nil, false
	}
	for e := es.head; e != nil; e = e.next {
		if e.hashCode == h && e.key == key.LocalIndex() {
			return e.value, true
		}

	}
	return nil, false
}
Beispiel #3
0
// Removes and returns the entry associated with the specified key
// in the Collection.
//
// Returns if there was a mapping for key and the associated entry
func (c Collection) removeEntryForKey(key *engine.ObjectIndex) (*entry, bool) {
	//hashCode := 0
	//if key != nil {
	//hashCode = hash(key.HashCode())
	//}
	hash := hash(key.GetId())
	i := indexFor(hash, c.capacity)
	es := c.table[i]
	pre := es.head
	for e := es.head; e != nil; e = e.next {
		if e.hashCode == hash && e.key == key.LocalIndex() {
			pre.next = e.next
			es.size--
			c.size--
		} //if
		pre = e
	}
	return nil, false
}
Beispiel #4
0
// Returns the entry associated with the specified key in the
// Collection.  Returns nil if the Collection contains no mapping
// for the key.
func (c Collection) getEntry(key *engine.ObjectIndex) *entry {
	//hashCode := 0
	//if key != nil {
	//	hashCode = hash(key.HashCode())
	//}
	h := hash(key.GetId())
	es := c.table[indexFor(h, c.capacity)]
	if es == nil {
		return nil
	}
	for e := es.head; e != nil; e = e.next {
		if e.hashCode == key.LocalHash() && e.key == key.LocalIndex() {
			return e
		}

	}
	return nil
}