Esempio n. 1
0
// Small demo of the common functions in the bag package.
func Example_usage() {
	// Create a new bag with some integers in it
	b := bag.New()
	for i := 0; i < 10; i++ {
		b.Insert(i)
	}
	b.Insert(8)
	// Remove every odd integer
	for i := 1; i < 10; i += 2 {
		b.Remove(i)
	}
	// Print the element count of all numbers
	for i := 0; i < 10; i++ {
		fmt.Printf("#%d: %d\n", i, b.Count(i))
	}
	// Calculate the sum with a Do iteration
	sum := 0
	b.Do(func(val interface{}) {
		sum += val.(int)
	})
	fmt.Println("Sum:", sum)
	// Output:
	// #0: 1
	// #1: 0
	// #2: 1
	// #3: 0
	// #4: 1
	// #5: 0
	// #6: 1
	// #7: 0
	// #8: 2
	// #9: 0
	// Sum: 28
}
Esempio n. 2
0
// Creates a new derived utility based on two existing ones.
func newComboUtility(combinator Combinator) *comboUtility {
	return &comboUtility{
		combinator: combinator,
		children:   bag.New(),
		reset:      true,
	}
}
Esempio n. 3
0
// Creates a new data source utility and associated a transformation curve.
func newInputSetUtility(curve Curve, nonZero bool) *inputSetUtility {
	return &inputSetUtility{
		curve:   curve,
		nonZero: nonZero,
		members: make(map[int]*inputUtility),
		deps:    bag.New(),
	}
}
Esempio n. 4
0
// Creates a new data source utility and associated a transformation curve.
func newInputUtility(curve Curve, nonZero bool) *inputUtility {
	return &inputUtility{
		curve:    curve,
		nonZero:  nonZero,
		children: bag.New(),
		reset:    true,
	}
}
Esempio n. 5
0
// Creates a new derived utility set based on two existing ones.
func newComboSetUtility(combinator Combinator, srcA, srcB utility) *comboSetUtility {
	return &comboSetUtility{
		combinator: combinator,
		srcA:       srcA,
		srcB:       srcB,
		members:    make(map[int]*comboUtility),
		deps:       bag.New(),
	}
}
Esempio n. 6
0
// Creates a new undirected graph.
func New(vertices int) *Graph {
	g := &Graph{
		nodes: vertices,
		infos: make(map[int]interface{}),
		edges: make([]*bag.Bag, vertices),
	}
	for i := 0; i < vertices; i++ {
		g.edges[i] = bag.New()
	}
	return g
}