On Tue, Aug 23, 2011 at 12:48:07PM +0200, Jan Friesse wrote:
Angus,
I'm afraid that I antedate answer, but I will still ask.
What guarantees gives me iteration? I'm especially interested answer for:
- I have iterator 1 in the middle, and somebody will delete item right
after iterator 1 (middle + 1), what will happen? Or more generally,
somebody deletes items middle + n, where n = <1, no_items - middle>
The maps currently will not handle these situations well :(
I would need to reference count the nodes to support that.
- Iterator on the beginning, somebody will add item on the end. Will I
get that item.
This should be OK (not tested though).
- I have iterator 1 and iterator 2 on the beginning. Iterator 2 makes
some progress (lets say to the middle), and somebody will delete few
items in interval <0, middle> and add some items in same interval. What
iterator 1 will see?
The iterators are "live" and don't do snapshots/versioning.
What behaviour do you think we are going to need?
We could have stable and live iterators:
live: you see changes as they happen
stable: changes are queued until all stable iterators have completed
What's important to you, the stability of the iterator or that the
changes go in together (transaction-like)?
-Angus
Regards,
Honza
Angus Salkeld napsal(a):
> Honza, how is this API to you?
>
> You might want:
> - a different style of iterator?
> - more qb_map_destroy options
> > destroy map, but not data
> > destroy map and data
>
> Create map from another type of map:
> qb_hashtable_create_from(m, ...)
> So you can have a hashtable and then sort it by
> inserting into a skiplist.
>
> Other search options?
>
> Regards
> Angus
>
>
> On Mon, Aug 22, 2011 at 01:30:50PM +1000, Angus Salkeld wrote:
>> Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
> [...]
>> +/**
>> + * Create an unsorted map based on a hashtable.
>> + *
>> + * @param key_compare_func a user function to compare keys
>> + * @param key_compare_data a user pointer to be passed into the compare
function
>> + * @param key_destroy_func function to free the key
>> + * @param value_destroy_func function to free the data
>> + * @param max_size maximum size of the hashtable
>> + * @param hash_fn hash function
>> + *
>> + * @see qb_hash_pointer, qb_hash_char, qb_hash_string
>> + *
>> + * @return the map instance
>> + */
>> +qb_map_t* qb_hashtable_create(qb_compare_func key_compare_func,
>> + void *key_compare_data,
>> + qb_destroy_notifier_func key_destroy_func,
>> + qb_destroy_notifier_func value_destroy_func,
>> + size_t max_size,
>> + qb_hash_func hash_fn);
>> +
>> +/**
>> + * Create a sorted map using a skiplist.
>> + *
>> + * @param key_compare_func a user function to compare keys
>> + * @param key_compare_data a user pointer to be passed into the compare
function
>> + * @param key_destroy_func function to free the key
>> + * @param value_destroy_func function to free the data
>> + *
>> + * @return the map instance
>> + */
>> +qb_map_t* qb_skiplist_create(qb_compare_func key_compare_func,
>> + void* key_compare_data,
>> + qb_destroy_notifier_func key_destroy_func,
>> + qb_destroy_notifier_func value_destroy_func);
>> +
>> +/**
>> + * Inserts a new key and value into a qb_map_t.
>> + *
>> + * If the key already exists in the qb_map_t, it gets replaced by the new key.
>> + * If you supplied a value_destroy_func when creating the qb_map_t,
>> + * the old value is freed using that function. If you supplied a
>> + * key_destroy_func when creating the qb_map_t, the old key is freed using
>> + * that function.
>> + */
>> +void qb_map_put(qb_map_t *map, const void* key, const void* value);
>> +
>> +/**
>> + * Gets the value corresponding to the given key.
>> + */
>> +void* qb_map_get(qb_map_t *map, const void* key);
>> +
>> +/**
>> + * Removes a key/value pair from a map.
>> + *
>> + * The key and value are freed using the supplied destroy functions,
>> + * otherwise you have to make sure that any dynamically allocated
>> + * values are freed yourself. If the key does not exist in the map,
>> + * the function does nothing.
>> + */
>> +int32_t qb_map_rm(qb_map_t *map, const void* key);
>> +
>> +/**
>> + * Get the number of items in the map.
>> + */
>> +size_t qb_map_count_get(qb_map_t *map);
>> +
>> +/**
>> + * Calls the given function for each of the key/value pairs in the map.
>> + *
>> + * The function is passed the key and value of each pair, and the given data
>> + * parameter. The map is traversed in sorted order.
>> + */
>> +void qb_map_foreach(qb_map_t *map, qb_transverse_func func, void* user_data);
>> +
>> +/**
>> + * Destroy the map, removes all the items from the map.
>> + */
>> +void qb_map_destroy(qb_map_t *map);
>> +
_______________________________________________
quarterback-devel mailing list
quarterback-devel(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/quarterback-devel