Re: Comparing DS_HASH_TABLE objects
Eric Bezault <ericb-D6Qt/9opevxWk0Htik3J/[email protected]> Sun, 31 May 2009 23:47:42 +0200
| Newsgroups | gmane.comp.lang.eiffel.gobo.general |
|---|---|
| Message-ID | <[email protected]> |
Paul Cohen wrote: > On Sun, May 31, 2009 at 8:43 PM, Eric Bezault <ericb-D6Qt/9opevxWk0Htik3J/[email protected]> wrote: >>> How do I compare two DS_HASH_TABLE objects for object equality? >> I don't know what you mean. Do you want to consider two >> hash tables equal if the items they contain are equal? > > I am aware that there are different ways of defining equality between > two tables t1 and t2. My assumption was something like: > > t1.keys.is_equal (t2.keys) and then > for each key k1 in t1: > (t1 @ k1).is_equal (t2 @ k2) > > I don't think the 'equality_tester':s should be used since they have > more with how DS_HASH_TABLE:s work, than what they contain (though how > they work will of course affect what they contain!). I don't see how `equality_tester' has more to do with how hash table works than what you try to do. I guess you're confusing `equality_tester' with `key_equality_tester'. Which brings to my attention the fact that in order to be correct, hash table equality should use `key_equality_tester' to compare keys in your code above, not `is_equal'. Indeed keys might be equal in terms of `is_equal', but they might nevertheless represent two different keys in the hash table (which uses `key_equality_ tester' for that). >> If so, what does it mean for two items in the hash tables >> to be equal? Should they have the same key? > > Yes and the items should be 'is_equal'. > >> If so, I don't >> think there is a feature for that in DS_HASH_TABLE. >> The implementation of `is_equal' uses '=' to compare >> items. > > Yes. I saw that. Why '=' and not 'is_equal'? But why `is_equal' and not any other kind of comparison? It uses '=' to compare items because `is_equal' is used in the postcondition of `copy/twin', and their implementation in hash table does not clone the items. > > I was just asking to make sure I hadn't overlooked anything and to see > if anyone had a standard idiom for this problem. > > I'm writing a test case for a situation where a DS_HASH_TABLE [ANY, > UC_STRING] is converted to another representation (JSON object) and > then back again, and I want to check that the two tables are "equal". > Obviously they won't contain the same objects so comparing by > reference isn't of much help. Note that I'm using ANY as the type for > my items. > > /Paul > -- Eric Bezault mailto:ericb-D6Qt/9opevxWk0Htik3J/[email protected] http://www.gobosoft.com ------------------------------------ To Post a message, send it to: [email protected] To Unsubscribe, send a blank message to: [email protected]! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/gobo-eiffel/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/gobo-eiffel/join (Yahoo! ID required) <*> To change settings via email: mailto:[email protected] mailto:[email protected] <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/