// splitTwo breaks up a node into two smaller nodes, if appropriate.
// This should only be called from the split() function.
499599
func (n *node) splitTwo(pageSize int) (*node, *node) {
	// Ignore the split if the page doesn't have at least enough nodes for
	// two pages or if the nodes can fit in a single page.
	if len(n.inodes) <= (minKeysPerPage*2) || n.sizeLessThan(pageSize) {
		return n, nil
	}

	// Determine the threshold before starting a new node.
	var fillPercent = n.bucket.FillPercent
	if fillPercent < minFillPercent {
		fillPercent = minFillPercent
	} else if fillPercent > maxFillPercent {
		fillPercent = maxFillPercent
	}
	threshold := int(float64(pageSize) * fillPercent)

	// Determine split position and sizes of the two pages.
	splitIndex, _ := n.splitIndex(threshold)

	// Split node into two separate nodes.
	// If there's no parent then we'll need to create one.
	if n.parent == nil {
		n.parent = &node{bucket: n.bucket, children: []*node{n}}
	}

	// Create a new node and add it to the parent.
	next := &node{bucket: n.bucket, isLeaf: n.isLeaf, parent: n.parent}
	n.parent.children = append(n.parent.children, next)

	// Split inodes across two nodes.
	next.inodes = n.inodes[splitIndex:]
	n.inodes = n.inodes[:splitIndex]

	// Update the statistics.
	n.bucket.tx.stats.Split++

	return n, next
}
1248327
func (n *node) splitIndex(threshold int) (index, sz int) {
	sz = pageHeaderSize

	// Loop until we only have the minimum number of keys required for the second page.
	for i := 0; i < len(n.inodes)-minKeysPerPage; i++ {
		index = i
		inode := n.inodes[i]
		elsize := n.pageElementSize() + len(inode.key) + len(inode.value)

		// If we have at least the minimum number of keys and adding another
		// node would put us over the threshold then exit and return.
		if i >= minKeysPerPage && sz+elsize > threshold {
			break
		}

		// Add the element size to the total size.
		sz += elsize
	}

	return
}
193483
func SplitMrt(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	if cap(data) < MRT_COMMON_HEADER_LEN { // read more
		return 0, nil, nil
	}
	//this reads the data
	hdr := &MRTHeader{}
	errh := hdr.DecodeFromBytes(data[:MRT_COMMON_HEADER_LEN])
	if errh != nil {
		return 0, nil, errh
	}
	totlen := int(hdr.Len + MRT_COMMON_HEADER_LEN)
	if len(data) < totlen { //need to read more
		return 0, nil, nil
	}
	return totlen, data[0:totlen], nil
}
822847
func SplitNetworkInTwo(network *net.IPNet) (*net.IPNet, *net.IPNet) {
	size, _ := network.Mask.Size()
	newMask := net.CIDRMask(size+1, 8*len(network.IP))

	ip2 := SliceSetOne(net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, uint(size))
	ip2 = SliceOr(network.IP, ip2)

	return &net.IPNet{IP: network.IP, Mask: newMask}, &net.IPNet{IP: ip2, Mask: newMask}
}
1034109
func (n *node) maybeSplitChild(i, maxItems int) bool {
	if len(n.children[i].items) < maxItems {
		return false
	}
	first := n.mutableChild(i)
	item, second := first.split(maxItems / 2)
	n.items.insertAt(i, item)
	n.children.insertAt(i+1, second)
	return true
}
1022275
func (rs *RowSplitter) Split(result [][][]sqltypes.Value, rows [][]sqltypes.Value) error {
	for _, row := range rows {
		k, err := rs.KeyResolver.keyspaceID(row)
		if err != nil {
			return err
		}
		for i, kr := range rs.KeyRanges {
			if key.KeyRangeContains(kr, k) {
				result[i] = append(result[i], row)
				break
			}
		}
	}
	return nil
}
862393
func Split(data []byte, atEOF bool) (advance int, token []byte, err error) {
	return split(false, data, atEOF)
}
251068
func (t *Tree) O() Node {
	n := t.A()
	for {
		switch t.peek().typ {
		case itemOr:
			n = newBinary(t.next(), n, t.A())
		default:
			return n
		}
	}
}
1196454
func SplitTagChunks(tags core.TagSlice, stopTag *core.Tag, chunkDelimiter *core.Tag) []core.TagSlice {
	chunks := make([]core.TagSlice, 0)

	tagIndex := 0
	for tagIndex < len(tags) {
		if tags[tagIndex].Equals(stopTag) {
			break
		}

		chunk := make([]*core.Tag, 1)
		chunk[0] = tags[tagIndex]
		tagIndex++

		foundStop := false

		for {
			if tags[tagIndex].Equals(chunkDelimiter) {
				chunk = append(chunk, tags[tagIndex])
				tagIndex++
				break
			}
			if tags[tagIndex].Equals(stopTag) {
				foundStop = true
				tagIndex++
				break
			} else {
				chunk = append(chunk, tags[tagIndex])
				tagIndex++
			}
		}
		chunks = append(chunks, chunk)

		if foundStop {
			break
		}
	}

	return chunks
}
916998
func Split(sql, separator string) []string {
	if len(separator) == 0 || len(sql) < len(separator) {
		return []string{sql}
	}
	l := &lexer{
		Sql: sql,
		Sep: separator,
		At:  0,
	}
	state := stateWhitespace
	for state != nil {
		state = state(l)
	}
	l.AddCurrent(1)
	return l.Batch
}
117474
func split(I, V, V2 []int, start, length, h int) {
	var i, j, k, x, jj, kk int

	// selection sort, for small buckets (don't split any further)
	if false && length < SelectionSortThreshold {
		for k = start; k < start+length; k += j {
			// the subarray [start:k] is already sorted
			j = 1
			// using the doubling technique from Karp, Miller, and Rosenberg,
			// V[I[i]+h] is our sorting key. See section 2.1 of
			// http://www.larsson.dogma.net/ssrev-tr.pdf
			x = V[I[k]+h]
			for i = 1; k+i < start+length; i++ {
				if V[I[k+i]+h] < x {
					// found a smaller value, x is the new smallest value
					x = V[I[k+i]+h]
					j = 0
				}
				if V[I[k+i]+h] == x {
					// since x is the smallest value we've seen so far, swap
					// the (k+i)th element next to it
					I[k+i], I[k+j] = I[k+j], I[k+i]
					// j is the number of values equal to the smallest value
					j++
				}
			}

			// at this point, x is the smallest value of the right part
			// of the array (the one we're still sorting) — and all values
			// equal to X are
			for i = 0; i < j; i++ {
				// commit group number for all values == x.
				// k + j -1 is a constant, they're all in the same group
				// (if j > 1, the group is not sorted yet).
				V2[I[k+i]] = k + j - 1
			}
			if j == 1 {
				// if there was only one value = x, it's a sorted group, mark
				// it as such in I (see faster suffix sorting)
				I[k] = -1
			}
		}
		return
	}

	// find pivot
	x = V[I[start+length/2]+h]
	jj = 0
	kk = 0
	for i = start; i < start+length; i++ {
		if V[I[i]+h] < x {
			// size of < bucket
			jj++
		}
		if V[I[i]+h] == x {
			// size of = bucket
			kk++
		}
	}
	// last index of < bucket
	jj += start
	// last index of = bucket
	kk += jj

	i = start
	j = 0
	k = 0
	// i goes from start of sorted array to end of < bucket
	for i < jj {
		if V[I[i]+h] < x {
			// ith element belongs in < bucket
			i++
		} else if V[I[i]+h] == x {
			// swap with = bucket
			I[i], I[jj+j] = I[jj+j], I[i]
			// j is our current position in the = bucket
			j++
		} else {
			// swap with > bucket
			I[i], I[kk+k] = I[kk+k], I[i]
			// k is our current position in the > bucket
			k++
		}
	}

	// at this point, the < bucket contains all < elements
	// but the = bucket might contain > elements, and vice versa
	for jj+j < kk {
		if V[I[jj+j]+h] == x {
			// (jj+j)th elements really belongs in =
			j++
		} else {
			// swap with > bucket
			I[jj+j], I[kk+k] = I[kk+k], I[jj+j]
			k++
		}
	}

	// at this point, the < bucket contains
	// all values < x, unsorted. same goes
	// for = and > buckets

	if jj > start {
		// < bucket is not empty, sort it
		split(I, V, V2, start, jj-start, h)
	}

	for i = 0; i < kk-jj; i++ {
		// commit ordering of = bucket
		// note that `kk - 1` is constant: all = elements have
		// the same group number, see Definition 3
		// in http://www.larsson.dogma.net/ssrev-tr.pdf
		V2[I[jj+i]] = kk - 1
	}
	if jj == kk-1 {
		// if = bucket is empty, that means we've
		// sorted the group (no need for further subsorts)
		I[jj] = -1
	}

	if start+length > kk {
		// > bucket is not empty, sort it
		split(I, V, V2, kk, start+length-kk, h)
	}
}
640890
func (m *Matter) split(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	delim, err := sniffDelim(data)
	if err != nil {
		return 0, nil, err
	}
	if _, ok := m.handlers[delim]; !ok {
		return 0, nil, ErrUnknownDelim
	}
	if x := bytes.Index(data, []byte(delim)); x >= 0 {
		// check the next delim index
		if next := bytes.Index(data[x+len(delim):], []byte(delim)); next > 0 {
			return next + len(delim), dropSpace(data[:next+len(delim)]), nil
		}
		return len(data), dropSpace(data[x+len(delim):]), nil
	}
	if atEOF {
		return len(data), data, nil
	}
	return 0, nil, nil
}
80839
func split(s string) <-chan string {
	ch := make(chan string)
	go func() {
		s = strings.Replace(s, " ", "", -1)
		if !strings.Contains(s, "(") {
			ch <- s
		} else {
			last := 0
			end := len(s)
			for info := range scan(s) {
				if last != info.openPos {
					ch <- s[last:info.openPos]
				}
				ch <- s[info.openPos:info.closePos]
				last = info.closePos
			}
			if last != end {
				ch <- s[last:]
			}
		}
		close(ch)
	}()
	return ch
}
290163
func splitTokens(tokens []string, sep string) (s splitted, err error) {
	index := index(tokens, sep)
	if index == -1 {
		return s, fmt.Errorf("'%s' not found in ['%s']", sep, strings.Join(tokens, "','"))
	}
	return splitted{
		Left:  tokens[:index],
		Right: tokens[index+1:],
	}, nil
}
1201768
func splitBound(edgeBound r2.Rect, uEnd, vEnd int, u, v float64) [2]r2.Rect {
	var childBounds = [2]r2.Rect{
		edgeBound,
		edgeBound,
	}

	if uEnd == 1 {
		childBounds[0].X.Lo = u
		childBounds[1].X.Hi = u
	} else {
		childBounds[0].X.Hi = u
		childBounds[1].X.Lo = u
	}

	if vEnd == 1 {
		childBounds[0].Y.Lo = v
		childBounds[1].Y.Hi = v
	} else {
		childBounds[0].Y.Hi = v
		childBounds[1].Y.Lo = v
	}

	return childBounds
}
1359850
func split(args, fields []string) []string {
	for _, arg := range fields {
		arr := strings.Fields(arg)
		args = append(args, arr...)
	}
	return args
}
211380
func splitNetworks(list []*NetworkToSplit) ([]*net.IPNet, error) {
	localPools := make([]*net.IPNet, 0, len(list))

	for _, p := range list {
		_, b, err := net.ParseCIDR(p.Base)
		if err != nil {
			return nil, fmt.Errorf("invalid base pool %q: %v", p.Base, err)
		}
		ones, _ := b.Mask.Size()
		if p.Size <= 0 || p.Size < ones {
			return nil, fmt.Errorf("invalid pools size: %d", p.Size)
		}
		localPools = append(localPools, splitNetwork(p.Size, b)...)
	}
	return localPools, nil
}