>> +/** Internal item of dictionary */
>> +struct cgroup_dictionary_item {
>> +    const char *name;
>> +    const char *value;
>> +    struct cgroup_dictionary_item *next;
>
> A singly linked list is sufficient for the dictionary?
> Is there a reason why you prefer a list to say a hash
> table? Is it because you care about the order?

Well, I think you have found the answers below... Maybe 'dictionary' is 
not the best term for the containers, it's really a stupid linked list. 
When someone needs it, it could be easily converted to dynamic array 
with random access; single linked list was just easier to implement. 
Basically I don't care how it is named and how it is internally 
implemented, as long as I can store (name, value) pairs in it and get 
them later in the same order - and I don't think that hash is the best 
structure for this.

>> +};
>> +
>> +/* Flags for cgroup_dictionary_create */
>> +/**
>> + * All items (i.e. both name and value strings) stored in the dictionary
>> + * should *NOT* be free()d on cgroup_dictionary_free(),
>> + * only the  dictionary helper structures should be freed.
>> + */
>> +#define CG_DICT_DONT_FREE_ITEMS             1
>> +
>
> What is a dictionary helper structure?

The 'overhead', i.e. currently the linked list of struct 
cgroup_dictionary_items. I'll write it more precisely.

>> +/**
>> + * Dictionary of (name, value) items.
>> + * The dictionary keeps its order, iterator iterates in the same order
>> + * as the items were added there.
>
> OK, so order is important

Yes, I think it is good idea to actually write the parameters in the 
same order as they appear in cgconfig.conf. I'll write it more precisely 
to the comments.

>
>> + * This structure should be opaque to users of the dictionary, underlying 
>> data
>> + * structure might change anytime and without warnings.
>> + */
>> +struct cgroup_dictionary {
>> +    struct cgroup_dictionary_item *head;
>> +    struct cgroup_dictionary_item *tail;
>> +    int flags;
>> +};
>> +
>> +/** Opaque iterator of an dictionary. */
>> +struct cgroup_dictionary_iterator {
>> +    struct cgroup_dictionary_item *item;
>> +};
>> +
>>   /**
>>    * per thread errno variable, to be used when return code is ECGOTHER
>>    */
>> @@ -164,6 +197,39 @@ int cgroup_config_insert_into_mount_table(char *name, 
>> char *mount_point);
>>   int cgroup_config_insert_into_namespace_table(char *name, char 
>> *mount_point);
>>   void cgroup_config_cleanup_mount_table(void);
>>   void cgroup_config_cleanup_namespace_table(void);
>> +
>> +/**
>> + * Create an empty dictionary.
>> + */
>> +extern int cgroup_dictionary_create(struct cgroup_dictionary **dict,
>> +            int flags);
>> +/**
>> + * Add an item to existing dictionary.
>> + */
>> +extern int cgroup_dictionary_add(struct cgroup_dictionary *dict,
>> +            const char *name, const char *value);
>> +/**
>> + * Fully destroy existing dictionary. Depending on flags passed to
>> + * cgroup_dictionary_create(), names and values might get destroyed too.
>> + */
>> +extern int cgroup_dictionary_free(struct cgroup_dictionary *dict);
>> +
>> +/**
>> + * Start iterating through a dictionary. The items are returned in the same
>> + * order as they were added using cgroup_dictionary_add().
>> + */
>> +extern int cgroup_dictionary_iterator_begin(struct cgroup_dictionary *dict,
>> +            void **handle, const char **name, const char **value);
>> +/**
>> + * Continue iterating through the dictionary.
>> + */
>> +extern int cgroup_dictionary_iterator_next(void **handle,
>> +            const char **name, const char **value);
>> +/**
>> + * Finish iteration through the dictionary.
>> + */
>> +extern void cgroup_dictionary_iterator_end(void **handle);
>> +
>>   __END_DECLS
>>
>


------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to