https://bugzilla.novell.com/show_bug.cgi?id=328036#c9





--- Comment #9 from Robert Jordan <[EMAIL PROTECTED]>  2007-09-25 18:00:21 MST 
---
[Unrelated to the bug]

Assuming that IDictionary.Contains() is actually an O(1) operation, you could
implement Equals more efficiently w/out sorting by simply probing if a key
from d1 is in d2 and if their values are equal. It would be an O (n) operation,
whereas your algorithm is O (n log n).

If you're uncertain whether Contains() is actually an O(1), you can
use a third (true O(1)) dictionary:

Hashtable t = new Hashtable ();

foreach (DictionaryEntry e in d1) {
    t[e.Key] = e.Value;
}

foreach (DictionaryEntry e in d2) {
    if (!t.Contains (e.Key))
        return false;

    value = t[e.Key];
    if (value != e.Value)
        return false;
}

This is also an O (n) operation.

For corner cases like "null" keys, you'd need special handling,
because Hashtable doesn't support it.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
_______________________________________________
mono-bugs maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-bugs

Reply via email to