'Insert the firstbits that start with fb using addr_vers and
are first seen in block_id.  Return the count of rows
inserted.
fb -- string, not a firstbits using addr_vers in any ancestor
of block_id
ids -- set of ids of all pubkeys first seen in block_id whose
firstbits start with fb
full -- map from pubkey_id to full firstbits'

def do_firstbits(store, addr_vers, block_id, fb, ids, full):

    if (len(ids) <= 1):
        for pubkey_id in ids:
            store.insert_firstbits(pubkey_id, block_id, addr_vers, fb)
        return len(ids)
    pubkeys = {}
    for pubkey_id in ids:
        s = full[pubkey_id]
        if (s == fb):
            store.cant_do_firstbits(addr_vers, block_id, pubkey_id)
            continue
        fb1 = (fb + s[len(fb)])
        ids1 = pubkeys.get(fb1)
        if (ids1 is None):
            ids1 = set()
            pubkeys[fb1] = ids1
        ids1.add(pubkey_id)
    count = 0
    for (fb1, ids1) in pubkeys.iteritems():
        count += store.do_firstbits(addr_vers, block_id, fb1, ids1, full)
    return count
