type key … type bitpos … type prefix … // branchingBit returns the position of the first bit in `x` and `y` // that are not equal. func branchingBit(x, y prefix) bitpos { … } // zeroBit returns true if k has a 0 bit at position `b`. func zeroBit(k prefix, b bitpos) bool { … } // matchPrefix returns true if a prefix k matches a prefix p up to position `b`. func matchPrefix(k prefix, p prefix, b bitpos) bool { … } // mask returns a prefix of `k` with all bits after and including `b` zeroed out. // // In big endian encoding, this value is the [64-(m-1)] most significant bits of k // followed by a `0` bit at bitpos m, followed m-1 `1` bits. // Examples: // // prefix(0b1011) for a bitpos 0b0100 represents the keys: // 0b1000, 0b1001, 0b1010, 0b1011, 0b1100, 0b1101, 0b1110, 0b1111 // // This mask function has the property that if matchPrefix(k, p, b), then // k <= p if and only if zeroBit(k, m). This induces binary search tree tries. // See Okasaki & Gill for more details about this choice of mask function. // // mask is idempotent for a given `b`, i.e. mask(mask(p, b), b) == mask(p,b). func mask(k prefix, b bitpos) prefix { … } // ord returns true if m comes before n in the bit ordering. func ord(m, n bitpos) bool { … } // prefixesOverlap returns true if there is some key a prefix `p` for bitpos `m` // can hold that can also be held by a prefix `q` for some bitpos `n`. // // This is equivalent to: // // m ==n && p == q, // higher(m, n) && matchPrefix(q, p, m), or // higher(n, m) && matchPrefix(p, q, n) func prefixesOverlap(p prefix, m bitpos, q prefix, n bitpos) bool { … }