/* Initializes lf_hash, the arguments are compatible with hash_init @note element_size sets both the size of allocated memory block for lf_alloc and a size of memcpy'ed block size in lf_hash_insert. Typically they are the same, indeed. But LF_HASH::element_size can be decreased after lf_hash_init, and then lf_alloc will allocate larger block that lf_hash_insert will copy over. It is desireable if part of the element is expensive to initialize - for example if there is a mutex or DYNAMIC_ARRAY. In this case they should be initialize in the LF_ALLOCATOR::constructor, and lf_hash_insert should not overwrite them. See wt_init() for example. As an alternative to using the above trick with decreasing LF_HASH::element_size one can provide an "initialize" hook that will finish initialization of object provided by LF_ALLOCATOR and set element key from object passed as parameter to lf_hash_insert instead of doing simple memcpy. */ voidlf_hash_init2(LF_HASH *hash, uint element_size, uint flags, uint key_offset, uint key_length, hash_get_key_function get_key, CHARSET_INFO *charset, lf_hash_func *hash_function, lf_allocator_func *ctor, lf_allocator_func *dtor, lf_hash_init_func *init){ lf_alloc_init2(&hash->alloc, sizeof(LF_SLIST) + element_size, offsetof(LF_SLIST, key), ctor, dtor); lf_dynarray_init(&hash->array, sizeof(LF_SLIST *)); hash->size = 1; hash->count = 0; hash->element_size = element_size; hash->flags = flags; hash->charset = charset ? charset : &my_charset_bin; hash->key_offset = key_offset; hash->key_length = key_length; hash->get_key = get_key; hash->hash_function = hash_function ? hash_function : cset_hash_sort_adapter; hash->initialize = init; DBUG_ASSERT(get_key ? !key_offset && !key_length : key_length); }