Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[std] make haxe.ds.HashMap unify with Iterable, closes #9055 #9066

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions std/haxe/ds/HashMap.hx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import haxe.iterators.HashMapKeyValueIterator;

@see https://haxe.org/manual/std-Map.html
**/
abstract HashMap<K:{function hashCode():Int;}, V>(HashMapData<K, V>) {
abstract HashMap<K:{function hashCode():Int;}, V>(HashMapData<K, V>) to Iterable<V> to KeyValueIterable<K, V> {
/**
Creates a new HashMap.
**/
Expand Down Expand Up @@ -90,14 +90,14 @@ abstract HashMap<K:{function hashCode():Int;}, V>(HashMapData<K, V>) {
See `Map.iterator`
**/
public inline function iterator() {
return this.values.iterator();
return this.iterator();
}

/**
See `Map.keyValueIterator`
**/
public inline function keyValueIterator():HashMapKeyValueIterator<K, V> {
return new HashMapKeyValueIterator(cast this);
return this.keyValueIterator();
}

/**
Expand All @@ -117,4 +117,12 @@ private class HashMapData<K:{function hashCode():Int;}, V> {
keys = new IntMap();
values = new IntMap();
}

public inline function iterator() {
return values.iterator();
}

public inline function keyValueIterator():HashMapKeyValueIterator<K, V> {
return new HashMapKeyValueIterator(cast this);
}
}
4 changes: 4 additions & 0 deletions tests/unit/src/unit/TestHashMap.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package unit;

import haxe.ds.HashMap;

using Lambda;

class TestHashMap extends Test {
function test() {
var grid = new HashMap<Point, String>();
Expand All @@ -24,6 +26,8 @@ class TestHashMap extends Test {
asserts++;
}
eq(4, asserts);

eq(4, grid.count(_ -> true));
}
}

Expand Down