本文整理汇总了Golang中container/vector.Vector.Do方法的典型用法代码示例。如果您正苦于以下问题:Golang Vector.Do方法的具体用法?Golang Vector.Do怎么用?Golang Vector.Do使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类container/vector.Vector
的用法示例。
在下文中一共展示了Vector.Do方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: chooseNextEdgeByGeneration
func chooseNextEdgeByGeneration(T *quadratic.Map) *quadratic.Edge {
ActiveFaces := new(vector.Vector)
onGeneration := -1
T.Faces.Do(func(F interface{}) {
Fac := F.(*quadratic.Face)
if Fac.Value.(string) != "active" {
return
}
ActiveFaces.Push(Fac)
Fac.DoEdges(func(e *quadratic.Edge) {
//fmt.Fprintf(os.Stderr,"edge generation: %v onGen: %v\n",e.Generation,onGeneration)
if onGeneration < 0 || e.Generation < onGeneration {
onGeneration = e.Generation
}
})
})
activeEdges := new(generationOrderedEdges)
ActiveFaces.Do(func(F interface{}) {
Fac := F.(*quadratic.Face)
Fac.DoEdges(func(e *quadratic.Edge) {
if e.Generation != onGeneration {
return
}
activeEdges.Push(e)
})
})
//fmt.Fprintf(os.Stderr,"onGen: %v have %v active edges\n",onGeneration,activeEdges.Len())
sort.Sort(activeEdges)
return activeEdges.At(0).(*quadratic.Edge)
}
示例2: EvaluateTree
func (state *State) EvaluateTree(tree vector.Vector) {
tree.Do(func(elem interface{}) {
msg := elem.(IMessage)
println(msg.GetName())
msg.GetArguments().Do(func(item interface{}) {
arg := item.(IMessage)
println(arg.GetName())
})
})
}
示例3: VerifyRBTreeProperties
/**
From Introduction to Algorithms, 2/e
Red-Black Tree has the following properties
1. Every Node is either red or black
2. The root is black
3. Every leaf (NIL) is black
4. If a node is red, then both its children are black
5. For each node, all paths from the node to descendantat leaves
contain the same number of black nodes
*/
func VerifyRBTreeProperties(tree *RBTree, t *testing.T) {
if tree.root == NIL {
return
}
if tree.root.color != BLACK {
t.Errorf("(1) root color is not BLACK")
}
leafs := new(vector.Vector)
inorderTreeWalk(tree.root, func(n *Node) {
if n.Leaf() {
leafs.Push(n)
}
})
var numBlacks int = -1
leafs.Do(func(i interface{}) {
n := i.(*Node)
if n.Left != NIL { // NIL is always black
t.Errorf("left of leaf is not NIL")
}
if n.Right != NIL { // NIL is always black
t.Errorf("right of leaf is not NIL")
}
var blacks int = 0
for n != tree.root {
if n.color == BLACK {
blacks += 1
} else {
if n.Parent.color == RED { // property 4 failed
t.Errorf("(4) two consecutive RED nodes %d %d", n.Value.(int), n.Parent.Value.(int))
}
}
n = n.Parent
}
if numBlacks == -1 {
numBlacks = blacks
} else {
if numBlacks != blacks {
t.Errorf("(5) number of blacks differ. %d vs. %d", numBlacks, blacks)
}
}
})
}
示例4: Overlay
func (m *Map) Overlay(n *Map, mergeFaces func(interface{}, interface{}) (interface{}, os.Error)) (*Map, os.Error) {
o := NewMap()
CopiedEdges := new(vector.Vector)
m.Edges.Do(func(l interface{}) {
e := l.(*Edge)
if e.start.Point.Less(e.end.Point) {
f, g := NewEdgePair(NewVertex(e.start.Copy()), NewVertex(e.end.Copy()))
f.face = e.face
g.face = e.twin.face
f.Generation = e.Generation
g.Generation = e.twin.Generation
f.fromMap,g.fromMap = m,m
CopiedEdges.Push(f)
CopiedEdges.Push(g)
}
})
n.Edges.Do(func(l interface{}) {
e := l.(*Edge)
if e.start.Point.Less(e.end.Point) {
f, g := NewEdgePair(NewVertex(e.start.Copy()), NewVertex(e.end.Copy()))
f.face = e.face
g.face = e.twin.face
f.Generation = e.Generation
g.Generation = e.twin.Generation
f.fromMap,g.fromMap = n,n
CopiedEdges.Push(f)
CopiedEdges.Push(g)
}
})
Q := new(vector.Vector)
T := new(sweepStatus)
T.segments = new(vector.Vector)
CopiedEdges.Do(func(l interface{}) {
e, _ := l.(*Edge)
if e.start.Point.Less(e.end.Point) {
evt := new(sweepEvent)
evt.point = e.start.Point
evt.coincidentEdge = e
Q.Push(evt)
evt = new(sweepEvent)
evt.point = e.end.Point
evt.coincidentEdge = nil
Q.Push(evt)
}
})
heap.Init(Q)
for Q.Len() > 0 {
evt, _ := heap.Pop(Q).(*sweepEvent)
//fmt.Fprintf(os.Stderr,"event: %v\n",evt.point)
L := new(vector.Vector)
Lswp := new(sweepStatus)
Lswp.segments = L
Lswp.sweepLocation = evt.point
if evt.coincidentEdge != nil {
L.Push(evt.coincidentEdge)
}
for Q.Len() > 0 && evt.point.Equal(Q.At(0).(*sweepEvent).point) {
evt, _ := heap.Pop(Q).(*sweepEvent)
if evt.coincidentEdge != nil {
L.Push(evt.coincidentEdge)
}
}
sort.Sort(Lswp)
for i := 0; i < L.Len()-1; {
if L.At(i).(*Edge).Equal(L.At(i + 1).(*Edge)) {
L.At(i).(*Edge).newFace = L.At(i + 1).(*Edge).face
L.At(i).(*Edge).twin.newFace = L.At(i + 1).(*Edge).twin.face
L.At(i).(*Edge).fromMap = nil //no longer from a unique map
L.At(i).(*Edge).twin.fromMap = nil //no longer from a unique map
L.Delete(i + 1)
} else {
i++
}
}
//fmt.Fprintf(os.Stderr,"L: %v\n",L)
R := new(vector.Vector)
for i := 0; i < T.segments.Len(); {
e := T.segments.At(i).(*Edge)
if e.end.Point.Equal(evt.point) {
R.Push(e)
T.segments.Delete(i)
} else if e.Line().On(evt.point) {
return nil, os.NewError("intersection not at an endpoint")
} else {
i++
}
}
// Fill in handle event. You won't need the whole damn thing because
// Most of the time you just abort with non-terminal intersection
T.sweepLocation = evt.point
sort.Sort(T)
//fmt.Fprintf(os.Stderr,"status: %v\n",T.segments)
if L.Len() == 0 && R.Len() == 0 {
return nil, os.NewError("event point with no edges terminal at it " + evt.point.String() + fmt.Sprintf("current status: %v", T.segments))
} else if L.Len() == 0 {
//.........这里部分代码省略.........