X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fhtable%2Fhtable.h;h=61ed9170fda461779840f63db55295757a9bce8a;hp=e150c2ef0958065d3e289482d78dfe8267017a9b;hb=f359fde1b7c3ca60faebd4df710bf30a68784e27;hpb=7b56762984ce66f38728b542ca347bcb6fe3e981 diff --git a/ccan/htable/htable.h b/ccan/htable/htable.h index e150c2ef..61ed9170 100644 --- a/ccan/htable/htable.h +++ b/ccan/htable/htable.h @@ -74,6 +74,25 @@ bool htable_init_sized(struct htable *ht, */ void htable_clear(struct htable *ht); +/** + * htable_copy - duplicate a hash table. + * @dst: the hash table to overwrite + * @src: the hash table to copy + * + * Only fails on out-of-memory. + * + * Equivalent to (but faster than): + * if (!htable_init_sized(dst, src->rehash, src->priv, 1U << src->bits)) + * return false; + * v = htable_first(src, &i); + * while (v) { + * htable_add(dst, v); + * v = htable_next(src, i); + * } + * return true; + */ +bool htable_copy(struct htable *dst, const struct htable *src); + /** * htable_rehash - use a hashtree's rehash function * @elem: the argument to rehash()