[asterisk-dev] [Code Review]: RFC for proposed astobj2 API container enhancements

Mark Michelson reviewboard at asterisk.org
Thu Mar 29 17:10:42 CDT 2012



> On March 29, 2012, 9:50 a.m., Mark Michelson wrote:
> > /trunk/include/asterisk/astobj2.h, lines 938-946
> > <https://reviewboard.asterisk.org/r/1835/diff/1/?file=26924#file26924line938>
> >
> >     How do you plan to detect a duplicate object?
> 
> rmudgett wrote:
>     Duplicate objects are easily detectable in sorted containers.  Unsorted containers must be searched.  I will note that the duplicate option is only applicable to sorted containers.
> 
> Mark Michelson wrote:
>     To clarify my question more, how do you differentiate between duplicate objects and objects with duplicate keys?
>     
>     I suppose that my definition of what a duplicate key is may be different from yours. For instance, if you have an object type foo, and it has a field bar within it like:
>     
>     struct foo {
>         char *bar;
>     };
>     
>     Then it is reasonable to assume that we might compare foos by using the comparison function:
>     
>     int cmp_foo(void *obj, void *arg, int flags)
>     {
>         struct foo *foo1 = obj;
>         struct foo *foo2 = arg;
>         return !strcmp(foo1->bar, foo2->bar) ? CMP_MATCH : 0;
>     }
>     
>     Similarly, we may choose to hash foos using the hash function
>     
>     int hash_foo(const void *obj, int flags)
>     {
>         struct foo *foo = obj;
>         return ast_str_hash(foo->bar);
>     }
>     
>     Now, how do we determine if two foos are duplicates? Is it because cmp_foo() returns CMP_MATCH? Doesn't that just mean the objects have duplicate keys? Or would two foos be considered to have duplicate keys if hash_foo() returns the same value for two foos? If the latter, then what does it mean for an object to have duplicate keys if it is not in a hash container?
> 
> rmudgett wrote:
>     Your elaboration further points out reasons why the container must be provided a sort_fn to use the duplicate options.  Otherwise there is no way to tell if an object is a duplicate except if the object pointer is equal.

If I've distilled what you've just said correctly, then sort_fn() is what is used to determine whether an item is a duplicate object, but the cmp_fn() is what is used to determine whether two objects have duplicate keys. So for some objects, it's possible these definitions could overlap, but for others, it's not quite the case.


- Mark


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/1835/#review5906
-----------------------------------------------------------


On March 29, 2012, 5:06 p.m., rmudgett wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/1835/
> -----------------------------------------------------------
> 
> (Updated March 29, 2012, 5:06 p.m.)
> 
> 
> Review request for Asterisk Developers, Mark Michelson and Matt Jordan.
> 
> 
> Summary
> -------
> 
> RFC to add proposed API enhancements for containers.
> 
> API allows for sorted containers, insertion options, duplicate handling options, and traversal order options.
> 
> Also has several documentation corrections.
> 
> 
> Diffs
> -----
> 
>   /trunk/include/asterisk/astobj2.h 360828 
> 
> Diff: https://reviewboard.asterisk.org/r/1835/diff
> 
> 
> Testing
> -------
> 
> It compiles but doesn't link.  This is a RFC.  :)
> 
> 
> Thanks,
> 
> rmudgett
> 
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20120329/4a4ccbfd/attachment.htm>


More information about the asterisk-dev mailing list