// Hyper returns a virtual hypercube graph with 2ⁿ vertices.
// Two vertices of a hypercube are adjacent when their binary
// representations differ in a single digit.
162279
func Hyper(n int) *Virtual {
	switch {
	case n < 0:
		return nil
	case n == 0:
		return singleton()
	case n == 1:
		return line(2)
	case n > bitsPerWord-2:
		panic("n=" + strconv.Itoa(n) + " too big; max=" + strconv.Itoa(bitsPerWord-2))
	}

	res := generic0(1<<uint(n), func(v, w int) (edge bool) {
		d := v ^ w
		return d&-d == d
	})

	res.degree = func(v int) (deg int) {
		return n
	}

	res.visit = func(v int, a int, do func(w int, c int64) bool) (aborted bool) {
		if v >= a {
			for b := 1 << uint(n); b > 0; b >>= uint(1) {
				if v&b == 0 {
					continue
				}
				if w := v ^ b; w >= a && do(w, 0) {
					return true
				}
			}
		}
		for b := 1; b < 1<<uint(n); b <<= uint(1) {
			if v&b != 0 {
				continue
			}
			if w := v ^ b; w >= a && do(w, 0) {
				return true
			}
		}
		return
	}
	return res
}
1135845
func linear(v0, v1, v2, v3 *uint32) {
	t0 := ((*v0 << 13) | (*v0 >> (32 - 13)))
	t2 := ((*v2 << 3) | (*v2 >> (32 - 3)))
	t1 := *v1 ^ t0 ^ t2
	t3 := *v3 ^ t2 ^ (t0 << 3)
	*v1 = (t1 << 1) | (t1 >> (32 - 1))
	*v3 = (t3 << 7) | (t3 >> (32 - 7))
	t0 ^= *v1 ^ *v3
	t2 ^= *v3 ^ (*v1 << 7)
	*v0 = (t0 << 5) | (t0 >> (32 - 5))
	*v2 = (t2 << 22) | (t2 >> (32 - 22))
}
1100420
func Graph(disableList []string) (ordered []*Registration) {
	register.RLock()
	defer register.RUnlock()
	for _, d := range disableList {
		for i, r := range register.r {
			if r.ID == d {
				register.r = append(register.r[:i], register.r[i+1:]...)
				break
			}
		}
	}

	added := map[*Registration]bool{}
	for _, r := range register.r {

		children(r.ID, r.Requires, added, &ordered)
		if !added[r] {
			ordered = append(ordered, r)
			added[r] = true
		}
	}
	return ordered
}
566206
func (g *UndirectedGraph) Edge(u, v graph.Node) graph.Edge {
	return g.EdgeBetween(u, v)
}
1308811
func (g1 *Virtual) Join(g2 *Virtual, bridge EdgeSet) *Virtual {
	n := g1.order + g2.order
	t := g1.order // transpose
	switch {
	case n == 0:
		return null
	case g1.order == 0:
		return g2
	case g2.order == 0:
		return g1
	}

	if bridge.Cost == nil {
		bridge.Cost = zero
	}
	joinCost := func(v, w int) int64 {
		switch {
		case v < t && w < t:
			return g1.cost(v, w)
		case v >= t && w >= t:
			return g2.cost(v-t, w-t)
		default:
			return bridge.Cost(v, w)
		}
	}

	var noFilter bool
	if bridge.Keep == nil {
		noFilter = true
		bridge.Keep = alwaysEdge
	}
	s1 := bridge.From.And(Range(0, t))
	s2 := bridge.To.And(Range(t, g2.order+t))

	res := generic(n, joinCost, func(v, w int) (edge bool) {
		switch {
		case v < t && w < t:
			return g1.edge(v, w)
		case v >= t && w >= t:
			return g2.edge(v-t, w-t)
		case !bridge.Keep(v, w):
			return false
		default:
			return s1.Contains(v) && s2.Contains(w) ||
				s1.Contains(w) && s2.Contains(v)
		}
	})

	if noFilter {
		res.degree = func(v int) (deg int) {
			switch {
			case v < t:
				deg = g1.degree(v)
				if s1.Contains(v) {
					deg += s2.size()
				}
				return
			default:
				deg = g2.degree(v - t)
				if s2.Contains(v) {
					deg += s1.size()
				}
				return
			}
		}
	}

	res.visit = func(v int, a int, do func(w int, c int64) bool) (aborted bool) {
		if v < t {
			if g1.visit(v, a, do) {
				return true
			}
			if !s1.Contains(v) {
				return
			}
			for _, in := range s2.And(Range(a, n)).set {
				for w := in.a; w < in.b; w++ {
					if bridge.Keep(v, w) && do(w, bridge.Cost(v, w)) {
						return true
					}
				}
			}
			return
		}
		if s2.Contains(v) {
			for _, in := range s1.And(Range(a, n)).set {
				for w := in.a; w < in.b; w++ {
					if bridge.Keep(v, w) && do(w, bridge.Cost(v, w)) {
						return true
					}
				}
			}
		}
		return g2.visit(v-t, max(0, a-t), func(w int, c int64) bool {
			return do(w+t, c)
		})
	}
	return res
}
1061557
func (g *Graph) Add(v Vertex) Vertex {
	g.init()
	g.vertices.Add(v)
	g.debug.Add(v)
	return v
}
1315537
func (g *Mutable) Degree(v int) int {
	return len(g.edges[v])
}
582702
func (g *graphObject) V(call goja.FunctionCall) goja.Value {
	return g.Vertex(call)
}
1271314
func (l *Loop) Edge(i int) Edge {
	return Edge{l.Vertex(i), l.Vertex(i + 1)}
}
207399
func BasicEdge(source, target Vertex) Edge {
	return &basicEdge{S: source, T: target}
}
712543
func (g *Graph) flow() {
	n := 0
	var nod *Graph

	for i := 0; i < g.Len(); i++ {

		node := g.Out[i]
		s := node.ThisString()

		if s == TypeIf || s == TypeFor {
			n++
			if n == 1 {
				nod = node.Add(TypeTemplate)
				continue
			}
		}

		if s == TypeElse {
			if n == 1 {
				nod.flow()
				nod = node
				continue
			}
		}

		if s == TypeEnd {
			n--
			if n == 0 {
				nod.flow()
				g.DeleteAt(i)
				i--
				continue
			}
		}

		if n > 0 {
			nod.Add(node)
			g.DeleteAt(i)
			i--
		}
	}

}
577599
func Cycle(n int) *Virtual {
	switch {
	case n < 0:
		return nil
	case n == 0:
		return null
	case n == 1:
		return singleton()
	case n == 2:
		return edge()
	}

	g := generic0(n, func(v, w int) (edge bool) {
		switch v - w {
		case 1 - n, -1, 1, n - 1:
			edge = true
		}
		return
	})

	// Precondition : n ≥ 3.
	g.degree = func(v int) int { return 2 }

	// Precondition : n ≥ 3.
	g.visit = func(v int, a int, do func(w int, c int64) bool) (aborted bool) {
		var w [2]int
		switch v {
		case 0:
			w = [2]int{1, n - 1}
		case n - 1:
			w = [2]int{0, n - 2}
		default:
			w = [2]int{v - 1, v + 1}
		}
		for _, w := range w {
			if w >= a && do(w, 0) {
				return true
			}
		}
		return
	}
	return g
}
1330690
func (g *Graph) Edges() []Edge {
	list := g.edges.List()
	result := make([]Edge, len(list))
	for i, v := range list {
		result[i] = v.(Edge)
	}

	return result
}
1021364
func (h *hasher) hash(n node, db *Database, force bool) (node, node, error) {
	// If we're not storing the node, just hashing, use available cached data
	if hash, dirty := n.cache(); hash != nil {
		if db == nil {
			return hash, n, nil
		}
		if !dirty {
			switch n.(type) {
			case *fullNode, *shortNode:
				return hash, hash, nil
			default:
				return hash, n, nil
			}
		}
	}
	// Trie not processed yet or needs storage, walk the children
	collapsed, cached, err := h.hashChildren(n, db)
	if err != nil {
		return hashNode{}, n, err
	}
	hashed, err := h.store(collapsed, db, force)
	if err != nil {
		return hashNode{}, n, err
	}
	// Cache the hash of the node for later reuse and remove
	// the dirty flag in commit mode. It's fine to assign these values directly
	// without copying the node first because hashChildren copies it.
	cachedHash, _ := hashed.(hashNode)
	switch cn := cached.(type) {
	case *shortNode:
		cn.flags.hash = cachedHash
		if db != nil {
			cn.flags.dirty = false
		}
	case *fullNode:
		cn.flags.hash = cachedHash
		if db != nil {
			cn.flags.dirty = false
		}
	}
	return hashed, cached, nil
}
936212
func (g *AcyclicGraph) Root() (Vertex, error) {
	roots := make([]Vertex, 0, 1)
	for _, v := range g.Vertices() {
		if g.UpEdges(v).Len() == 0 {
			roots = append(roots, v)
		}
	}

	if len(roots) > 1 {
		// TODO(mitchellh): make this error message a lot better
		return nil, fmt.Errorf("multiple roots: %#v", roots)
	}

	if len(roots) == 0 {
		return nil, fmt.Errorf("no roots found")
	}

	return roots[0], nil
}
1062789
func (ci CellID) VertexNeighbors(level int) []CellID {
	halfSize := sizeIJ(level + 1)
	size := halfSize << 1
	f, i, j, _ := ci.faceIJOrientation()

	var isame, jsame bool
	var ioffset, joffset int
	if i&halfSize != 0 {
		ioffset = size
		isame = (i + size) < maxSize
	} else {
		ioffset = -size
		isame = (i - size) >= 0
	}
	if j&halfSize != 0 {
		joffset = size
		jsame = (j + size) < maxSize
	} else {
		joffset = -size
		jsame = (j - size) >= 0
	}

	results := []CellID{
		ci.Parent(level),
		cellIDFromFaceIJSame(f, i+ioffset, j, isame).Parent(level),
		cellIDFromFaceIJSame(f, i, j+joffset, jsame).Parent(level),
	}

	if isame || jsame {
		results = append(results, cellIDFromFaceIJSame(f, i+ioffset, j+joffset, isame && jsame).Parent(level))
	}

	return results
}
557249
func (vs *VertexSlice) VertexData() []float32 {
	return vs.va.vertexData(vs.i, vs.j)
}