comparison src/elhash.c @ 4398:479443c0f95a

Have list hashes depend on the order of the contents, as is the case for vectors. src/ChangeLog addition: 2008-01-16 Aidan Kehoe <kehoea@parhasard.net> * elhash.c (internal_hash): Make short lists with the same contents in a different order hash distinctly. Gives better performance for things like three-element lists describing colours. Thank you Sebastian Freundt! tests/ChangeLog addition: 2008-01-16 Aidan Kehoe <kehoea@parhasard.net> * automated/hash-table-tests.el: Assert that two short lists with the same contents in distinct orders hash differently.
author Aidan Kehoe <kehoea@parhasard.net>
date Wed, 16 Jan 2008 15:20:51 +0100
parents 229bd619740a
children aae1994dfeec
comparison
equal deleted inserted replaced
4397:9e28067e3083 4398:479443c0f95a
1717 Hashcode 1717 Hashcode
1718 internal_hash (Lisp_Object obj, int depth) 1718 internal_hash (Lisp_Object obj, int depth)
1719 { 1719 {
1720 if (depth > 5) 1720 if (depth > 5)
1721 return 0; 1721 return 0;
1722 if (CONSP (obj)) 1722
1723 { 1723 if (CONSP(obj))
1724 /* no point in worrying about tail recursion, since we're not 1724 {
1725 going very deep */ 1725 Hashcode hash, h;
1726 return HASH2 (internal_hash (XCAR (obj), depth + 1), 1726 int s;
1727 internal_hash (XCDR (obj), depth + 1)); 1727
1728 depth += 1;
1729
1730 if (!CONSP(XCDR(obj)))
1731 {
1732 /* special case for '(a . b) conses */
1733 return HASH2(internal_hash(XCAR(obj), depth),
1734 internal_hash(XCDR(obj), depth));
1735 }
1736
1737 /* Don't simply tail recurse; we want to hash lists with the
1738 same contents in distinct orders differently. */
1739 hash = internal_hash(XCAR(obj), depth);
1740
1741 obj = XCDR(obj);
1742 for (s = 1; s < 6 && CONSP(obj); obj = XCDR(obj), s++)
1743 {
1744 h = internal_hash(XCAR(obj), depth);
1745 hash = HASH3(hash, h, s);
1746 }
1747
1748 return hash;
1728 } 1749 }
1729 if (STRINGP (obj)) 1750 if (STRINGP (obj))
1730 { 1751 {
1731 return hash_string (XSTRING_DATA (obj), XSTRING_LENGTH (obj)); 1752 return hash_string (XSTRING_DATA (obj), XSTRING_LENGTH (obj));
1732 } 1753 }