Skip to content

Commit

Permalink
Fix: isEmpty checking wrongly in ArrayList.
Browse files Browse the repository at this point in the history
  • Loading branch information
Heromyth committed Nov 16, 2021
1 parent bcda079 commit f907065
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions source/hunt/collection/AbstractList.d
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,10 @@ abstract class AbstractList(E) : AbstractCollection!E, List!E {
override size_t toHash() @trusted nothrow {
size_t hashCode = 1;
try {
static if (is(E == class)) {
foreach (E e; this)
static if (is(E == class) || is(E == interface)) {
foreach (E e; this) {
hashCode = 31 * hashCode + (e is null ? 0 : (cast(Object) e).toHash());
}
} else {
foreach (E e; this)
hashCode = 31 * hashCode + hashOf(e);
Expand Down
2 changes: 1 addition & 1 deletion source/hunt/collection/ArrayList.d
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class ArrayList(E) : AbstractList!E {
* @return <tt>true</tt> if this list contains no elements
*/
override bool isEmpty() {
return _array.length == 0;
return _size == 0;
}

/**
Expand Down
7 changes: 5 additions & 2 deletions source/hunt/collection/Map.d
Original file line number Diff line number Diff line change
Expand Up @@ -1114,8 +1114,11 @@ abstract class AbstractMapEntry(K, V) : MapEntry!(K,V) {

alias opCmp = Object.opCmp;


override size_t toHash() @trusted nothrow {
return hashOf(key) ^ hashOf(value);
static if(is(V == interface)) {
return hashOf(key) ^ hashOf(cast(Object)value);
} else {
return hashOf(key) ^ hashOf(value);
}
}
}

0 comments on commit f907065

Please sign in to comment.