Skip to content

Commit

Permalink
use same hashCode in seqs and lists as in vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
richhickey committed Jan 6, 2009
1 parent 2ea265f commit 467568d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/jvm/clojure/lang/ASeq.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ public boolean equals(Object obj){
public int hashCode(){
if(_hash == -1)
{
int hash = 0;
int hash = 1;
for(ISeq s = seq(); s != null; s = s.rest())
{
hash = Util.hashCombine(hash, Util.hash(s.first()));
hash = 31 * hash + (s.first() == null ? 0 : s.first().hashCode());
}
this._hash = hash;
}
return _hash;
}


//public Object reduce(IFn f) throws Exception{
// Object ret = first();
// for(ISeq s = rest(); s != null; s = s.rest())
Expand Down
5 changes: 5 additions & 0 deletions src/jvm/clojure/lang/PersistentList.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ public Object reduce(IFn f, Object start) throws Exception{

static class EmptyList extends Obj implements IPersistentList, Collection{

@Override
public int hashCode(){
return 1;
}

EmptyList(IPersistentMap meta){
super(meta);
}
Expand Down

0 comments on commit 467568d

Please sign in to comment.