static int ileaf_merge(struct btree *btree, void *vinto, void *vfrom) { struct ileaf *into = vinto, *from = vfrom; unsigned fromcount = icount(from); /* If "from" is empty, does nothing */ if (!fromcount) return 1; assert(ibase(from) > ibase(into)); tuxkey_t fromibase = ibase(from); unsigned count = icount(into); int hole = fromibase - ibase(into) + count; __be16 *dict = ileaf_dict(btree, into); __be16 *fromdict = ileaf_dict(btree, from); int need_size = hole * sizeof(*dict) + ileaf_need(btree, from); if (ileaf_free(btree, into) < need_size) return 0; /* Fill hole of dict until from_ibase */ unsigned limit = atdict(dict, count); __be16 __limit = cpu_to_be16(limit); while (hole--) { count++; *(dict - count) = __limit; } /* Copy data from "from" */ unsigned fromlimit = atdict(fromdict, fromcount); memcpy(into->table + limit, from->table, fromlimit); /* Adjust copying fromdict */ if (limit) { int i; for (i = 1; i <= fromcount; i++) add_idict(dict - i, limit); } veccopy(dict - count - fromcount, fromdict - fromcount, fromcount); into->count = cpu_to_be16(count + fromcount); return 1; }
static int ileaf_free(struct btree *btree, struct ileaf *ileaf) { return btree->sb->blocksize - ileaf_need(btree, ileaf) - sizeof(struct ileaf); }
static unsigned ileaf_free(struct btree *btree, vleaf *leaf) { return btree->sb->blocksize - ileaf_need(btree, leaf) - sizeof(struct ileaf); }