diff --git a/hashmap/hashmap.mbt b/hashmap/hashmap.mbt index 33bf52ae8..8af3da958 100644 --- a/hashmap/hashmap.mbt +++ b/hashmap/hashmap.mbt @@ -36,7 +36,7 @@ /// ``` #as_free_fn pub fn[K, V] HashMap::new(capacity? : Int = 8) -> HashMap[K, V] { - let capacity = capacity.next_power_of_two() + let capacity = capacity.next_power_of_two().max(8) { size: 0, capacity, diff --git a/hashmap/hashmap_test.mbt b/hashmap/hashmap_test.mbt index 8775fb293..b3e571eda 100644 --- a/hashmap/hashmap_test.mbt +++ b/hashmap/hashmap_test.mbt @@ -19,6 +19,12 @@ test "new" { inspect(m.length(), content="0") } +///| +test "new minimum capacity" { + let m : @hashmap.HashMap[Int, Int] = @hashmap.new(capacity=2) + inspect(m.capacity(), content="8") +} + ///| test "get" { let m = @hashmap.new()