func (n *MemPrefixNode) insert(z *cf.Zp, marray []*cf.Zp, bs *cf.Bitstring, depth int) error { n.updateSvalues(z, marray) n.numElements++ if n.IsLeaf() { if len(n.elements) > n.SplitThreshold() { err := n.split(depth) if err != nil { return err } } else { for _, nz := range n.elements { if nz.Cmp(z) == 0 { return fmt.Errorf("duplicate: %q", z.String()) } } n.elements = append(n.elements, z) return nil } } childIndex := NextChild(n, bs, depth) children, err := n.Children() if err != nil { return err } child := children[childIndex].(*MemPrefixNode) return child.insert(z, marray, bs, depth+1) }
// Insert a Z/Zp integer into the prefix tree func (t *MemPrefixTree) Insert(z *cf.Zp) error { if t.allElements.Has(z) { return fmt.Errorf("duplicate: %q", z.String()) } bs := cf.NewZpBitstring(z) marray, err := AddElementArray(t, z) if err != nil { return err } err = t.root.insert(z, marray, bs, 0) if err != nil { return err } t.allElements.Add(z) return nil }