Skip to content
Snippets Groups Projects
Unverified Commit 7fe9e24f authored by Yorick Peterse's avatar Yorick Peterse
Browse files

Rename HashMap to Map

In preparation for removing hash map literals we rename HashMap to Map,
which makes it a little bit easier to type.
parent 78bf415a
No related branches found
No related tags found
No related merge requests found
Showing
with 147 additions and 147 deletions
Loading
Loading
@@ -40,7 +40,7 @@ module Inkoc
OBJECT_CONST = 'Object'
TRAIT_CONST = 'Trait'
ARRAY_CONST = 'Array'
HASH_MAP_CONST = 'HashMap'
HASH_MAP_CONST = 'Map'
BLOCK_CONST = 'Block'
INTEGER_CONST = 'Integer'
FLOAT_CONST = 'Float'
Loading
Loading
Loading
Loading
@@ -522,7 +522,7 @@ module Inkoc
end
 
def on_send(node, body)
# HashMap literals need to be optimised before we process their
# Map literals need to be optimised before we process their
# arguments.
if node.hash_map_literal?
return on_hash_map_literal(node, body)
Loading
Loading
@@ -543,7 +543,7 @@ module Inkoc
)
end
 
# Optimises a HashMap literal.
# Optimises a Map literal.
#
# This method will turn this:
#
Loading
Loading
@@ -551,7 +551,7 @@ module Inkoc
#
# Into (effectively) the following:
#
# let hash_map = HashMap.new
# let hash_map = Map.new
#
# hash_map['a'] = 10
# hash_map['b'] = 20
Loading
Loading
@@ -568,7 +568,7 @@ module Inkoc
new_method = hash_map_type.lookup_method(Config::NEW_MESSAGE).type
set_method = hash_map_type.lookup_method(Config::SET_INDEX_MESSAGE).type
 
# Initialise an empty HashMap.
# Initialise an empty Map.
hash_map_reg = send_object_message(
hash_map_global_reg,
new_method.name,
Loading
Loading
Loading
Loading
@@ -48,7 +48,7 @@ module Inkoc
# def map!(T: Equal)(
# keys: Array!(T),
# values: Array!(T)
# ) -> HashMap!(T, T) {
# ) -> Map!(T, T) {
# ...
# }
#
Loading
Loading
@@ -56,17 +56,17 @@ module Inkoc
#
# Without this logic, the return type would be:
#
# HashMap!(K -> Equal, V -> Equal)
# Map!(K -> Equal, V -> Equal)
#
# This would then prevent us from doing the following, because
# `Equal` is not compatible with `String`:
#
# let mapping: HashMap!(String, String) = map([], [])
# let mapping: Map!(String, String) = map([], [])
#
# By removing the uninitialised type parameters, we essentially
# produce the following type in this example:
#
# HashMap!(K -> ?, V -> ?)
# Map!(K -> ?, V -> ?)
#
# This then allows the compiler to infer the proper type in the
# `let` above, instead of producing an error.
Loading
Loading
Loading
Loading
@@ -29,7 +29,7 @@ import std::block
import std::string
import std::array
import std::array_iter
import std::hash_map::(HashMap as _HashMap)
import std::map::(Map as _Map)
import std::inspect
import std::byte_array
import std::process
Loading
Loading
@@ -39,5 +39,5 @@ import std::integer::extensions
 
# These constants are re-exported so they're available to all modules by
# default. Core types such as String should be exposed in std::globals instead.
let HashMap = _HashMap
let Map = _Map
let Range = _Range
Loading
Loading
@@ -485,7 +485,7 @@ object Lexer {
 
def string(
quote: Integer,
replacements: HashMap!(Integer, Integer)
replacements: Map!(Integer, Integer)
) -> Token {
# Advance 1 for the opening quote.
@position += 1
Loading
Loading
@@ -540,7 +540,7 @@ object Lexer {
def append_string_byte(
buffer: ByteArray,
line_buffer: ByteArray,
replacements: HashMap!(Integer, Integer)
replacements: Map!(Integer, Integer)
) -> Boolean {
let current = current_byte
 
Loading
Loading
Loading
Loading
@@ -69,7 +69,7 @@ def remove(variable: String) -> Nil {
## import std::env
##
## env.variables # => %[ 'HOME': '/home/alice', ... ]
def variables -> HashMap!(String, String) {
def variables -> Map!(String, String) {
let names = _INKOC.env_variables
let map = %[]
 
Loading
Loading
Loading
Loading
@@ -300,7 +300,7 @@ object Member {
## structure.
object Layout {
## The members of this layout, mapped to their names.
@members: HashMap!(String, Member)
@members: Map!(String, Member)
 
## The size (in bytes) of this layout.
@size: Integer
Loading
Loading
@@ -310,7 +310,7 @@ object Layout {
@alignment: Integer
 
def init(
members: HashMap!(String, Member),
members: Map!(String, Member),
alignment: Integer,
size: Integer
) {
Loading
Loading
@@ -407,8 +407,8 @@ object LayoutBuilder {
## The types of all members, in the order they are defined in.
@types: Array!(Type)
 
## A HashMap that tracks which members have already been defined.
@existing: HashMap!(String, Boolean)
## A Map that tracks which members have already been defined.
@existing: Map!(String, Boolean)
 
## The alignment of the largest field.
@alignment: Integer
Loading
Loading
Loading
Loading
@@ -4,7 +4,7 @@
#! can't implement this earlier in modules such as `std::boolean`.
import std::conversion::ToString
import std::format::(self, Formatter, Inspect)
import std::hash_map::HashMap
import std::map::Map
import std::mirror
 
impl Inspect for Object {
Loading
Loading
@@ -179,12 +179,12 @@ impl Inspect for Array!(T) {
}
}
 
impl Inspect for HashMap!(K, V) {
## Returns a human-readable representation of this `HashMap`.
impl Inspect for Map!(K, V) {
## Returns a human-readable representation of this `Map`.
##
## # Examples
##
## Inspecting a `HashMap`:
## Inspecting a `Map`:
##
## let map = %['name': 'Alice', 'address': 'Foo Street']
##
Loading
Loading
@@ -193,7 +193,7 @@ impl Inspect for HashMap!(K, V) {
::format.inspect(self)
}
 
## Formats this `HashMap` into a human-readable representation.
## Formats this `Map` into a human-readable representation.
def format_for_inspect(formatter: Formatter) where K: Inspect, V: Inspect {
let last = length - 1
let mut index = 0
Loading
Loading
#! External and internal iteration for collections.
#!
#! Iterators are objects that can be used to traverse collections such as an
#! `Array` or a `HashMap`. Typically iterators are implemented in one of two
#! `Array` or a `Map`. Typically iterators are implemented in one of two
#! ways:
#!
#! 1. Internal iterators: these kind of iterators take care of the iteration
Loading
Loading
Loading
Loading
@@ -7,10 +7,10 @@ import std::operators::Equal
import std::process
import std::random
 
## The load factor of a `HashMap` before it should be resized.
## The load factor of a `Map` before it should be resized.
let LOAD_FACTOR = 0.75
 
## The default `Hasher` used for a `HashMap`.
## The default `Hasher` used for a `Map`.
##
## Different instances of a `DefaultHasher` may produce different hash values
## for the same object. The internal hashing algorithm may also change, and so
Loading
Loading
@@ -136,21 +136,21 @@ object Pair!(K: Hash + Equal, V) {
 
## An unordered hash map using linear probing and Robin Hood bucket stealing.
##
## The keys in a `HashMap` can be any object that implements the `Hash` and
## The keys in a `Map` can be any object that implements the `Hash` and
## `Equal` traits. The values can be of any type. It's possible to store keys
## (or values) of different types but this will require the use of `Dynamic`.
##
## A `HashMap` is unordered, meaning that keys can be returned in a (seemingly)
## A `Map` is unordered, meaning that keys can be returned in a (seemingly)
## random order.
##
## `HashMap` uses linear probing for finding values and Robin Hood hashing.
## `Map` uses linear probing for finding values and Robin Hood hashing.
## Removals are performed using backwards shift deletion. For more information
## on these algorithms you can refer to the following resources:
##
## * http://codecapsule.com/2013/11/11/robin-hood-hashing/
## * http://codecapsule.com/2013/11/17/robin-hood-hashing-backward-shift-deletion/
## * https://www.sebastiansylvan.com/post/robin-hood-hashing-should-be-your-default-hash-table-implementation/
object HashMap!(K: Hash + Equal, V) {
object Map!(K: Hash + Equal, V) {
## The state to use for creating hashers.
@random_state: RandomState
 
Loading
Loading
@@ -158,7 +158,7 @@ object HashMap!(K: Hash + Equal, V) {
## pair.
@buckets: Array!(?Pair!(K, V))
 
## The number of key-value pairs stored in this `HashMap`.
## The number of key-value pairs stored in this `Map`.
@length: Integer
 
## The number of values that can be stored before resizing.
Loading
Loading
@@ -169,37 +169,37 @@ object HashMap!(K: Hash + Equal, V) {
## time we want to check if we need to resize.
@resize_threshold: Integer
 
## Returns a `HashMap` using two arrays: one containing the keys and one
## Returns a `Map` using two arrays: one containing the keys and one
## containing the values.
##
## Using this method is semantically equivalent to creating a `HashMap` using
## `HashMap.new` and sending `[]=` to the `HashMap` for every key-value pair.
## Using this method is semantically equivalent to creating a `Map` using
## `Map.new` and sending `[]=` to the `Map` for every key-value pair.
## In other words, this:
##
## %['name': 'Alice']
##
## Is the same as this:
##
## let mut map = HashMap.new
## let mut map = Map.new
##
## map['name'] = 'Alice'
##
## # Compiler optimisation
##
## To remove the need for allocating two arrays for `HashMap` literals, the
## To remove the need for allocating two arrays for `Map` literals, the
## compiler may decide to optimise this method into separate `[]=` message
## sends as illustrated above.
##
## # Examples
##
## Creating a `HashMap` from two arrays:
## Creating a `Map` from two arrays:
##
## HashMap.from_array(['name'], ['Alice']) # => %['name': 'Alice']
## Map.from_array(['name'], ['Alice']) # => %['name': 'Alice']
static def from_array!(K: Hash + Equal, V)(
keys: Array!(K),
values: Array!(V)
) -> HashMap!(K, V) {
let mut map = HashMap.new
) -> Map!(K, V) {
let mut map = Map.new
let max_index = values.length - 1
 
keys.length == values.length
Loading
Loading
@@ -219,7 +219,7 @@ object HashMap!(K: Hash + Equal, V) {
map
}
 
## Creates a new, empty `HashMap`.
## Creates a new, empty `Map`.
def init {
@random_state = RandomState.new
@buckets = []
Loading
Loading
@@ -228,7 +228,7 @@ object HashMap!(K: Hash + Equal, V) {
@resize_threshold = 1
}
 
## Returns the buckets of this `HashMap`.
## Returns the buckets of this `Map`.
def buckets -> Array!(?Pair!(K, V)) {
@buckets
}
Loading
Loading
@@ -240,13 +240,13 @@ object HashMap!(K: Hash + Equal, V) {
##
## Removing a non-existing key:
##
## let mut map = HashMap.new
## let mut map = Map.new
##
## map.remove('name') # => Nil
##
## Removing an existing key:
##
## let mut map = HashMap.new
## let mut map = Map.new
##
## map['name'] = 'Alice'
##
Loading
Loading
@@ -275,9 +275,9 @@ object HashMap!(K: Hash + Equal, V) {
##
## # Examples
##
## Iterating over the keys and values of a `HashMap`:
## Iterating over the keys and values of a `Map`:
##
## let mut map = HashMap.new
## let mut map = Map.new
##
## map['name'] = 'Alice'
##
Loading
Loading
@@ -292,13 +292,13 @@ object HashMap!(K: Hash + Equal, V) {
}
 
## Returns an `Iterator` that iterates over all key-value pairs in this
## `HashMap`.
## `Map`.
##
## # Examples
##
## Iterating over all the key-value pairs:
##
## let mut map = HashMap.new
## let mut map = Map.new
##
## map['name'] = 'Alice'
##
Loading
Loading
@@ -328,13 +328,13 @@ object HashMap!(K: Hash + Equal, V) {
)
}
 
## Returns an `Iterator` visiting all the keys in this `HashMap`.
## Returns an `Iterator` visiting all the keys in this `Map`.
##
## # Examples
##
## Iterating over the keys in a `HashMap`:
## Iterating over the keys in a `Map`:
##
## let mut map = HashMap.new
## let mut map = Map.new
##
## map['name'] = 'Alice'
##
Loading
Loading
@@ -345,13 +345,13 @@ object HashMap!(K: Hash + Equal, V) {
iter.map do (pair) { pair.key }
}
 
## Returns an `Iterator` visiting all the values in this `HashMap`.
## Returns an `Iterator` visiting all the values in this `Map`.
##
## # Examples
##
## Iterating over the values in a `HashMap`:
## Iterating over the values in a `Map`:
##
## let mut map = HashMap.new
## let mut map = Map.new
##
## map['name'] = 'Alice'
##
Loading
Loading
@@ -366,7 +366,7 @@ object HashMap!(K: Hash + Equal, V) {
##
## # Examples
##
## Checking if a `HashMap` defines a key:
## Checking if a `Map` defines a key:
##
## let map = %['name': 'Alice']
##
Loading
Loading
@@ -397,7 +397,7 @@ object HashMap!(K: Hash + Equal, V) {
}
}
 
## Hashes the supplied key using the internal hasher of this `HashMap`.
## Hashes the supplied key using the internal hasher of this `Map`.
def _hash_key(key: K) -> Integer {
let hasher = @random_state.to_hasher
 
Loading
Loading
@@ -409,7 +409,7 @@ object HashMap!(K: Hash + Equal, V) {
## Inserts a new pair into `self`.
##
## The `Pair` to insert must be pre-hashed using the `Hasher` used internally
## by this `HashMap`, otherwise it might not be retrieved later.
## by this `Map`, otherwise it might not be retrieved later.
def _insert_pair(mut pair: Pair!(K, V)) {
let mut index = _desired_bucket(pair.hash)
 
Loading
Loading
@@ -521,13 +521,13 @@ object HashMap!(K: Hash + Equal, V) {
}
}
 
impl Equal for HashMap!(K, V) {
## Returns `True` if `self` and the given `HashMap` are identical to each
impl Equal for Map!(K, V) {
## Returns `True` if `self` and the given `Map` are identical to each
## other.
##
## # Examples
##
## Comparing two `HashMap` instances:
## Comparing two `Map` instances:
##
## %w['name': 'Alice'] == %w['name': 'Alice'] # => True
def ==(other: Self) -> Boolean where V: Equal {
Loading
Loading
@@ -551,20 +551,20 @@ impl Equal for HashMap!(K, V) {
}
}
 
impl Index!(K, V) for HashMap!(K, V) {
impl Index!(K, V) for Map!(K, V) {
## Returns the value for the given key, if any.
##
## # Examples
##
## Getting the value of a non-existing key:
##
## let map = HashMap.new
## let map = Map.new
##
## map['name'] # => Nil
##
## Getting the value of an existing key:
##
## let mut map = HashMap.new
## let mut map = Map.new
##
## map['name'] = 'Alice'
##
Loading
Loading
@@ -580,7 +580,7 @@ impl Index!(K, V) for HashMap!(K, V) {
}
}
 
impl SetIndex!(K, V) for HashMap!(K, V) {
impl SetIndex!(K, V) for Map!(K, V) {
## Inserts the given key and value into this map, returning the inserted
## value.
##
Loading
Loading
@@ -588,7 +588,7 @@ impl SetIndex!(K, V) for HashMap!(K, V) {
##
## Inserting a new key-value pair:
##
## let mut map = HashMap.new
## let mut map = Map.new
##
## map['name'] = 'Alice' # => 'Alice'
def []=(key: K, value: V) -> V {
Loading
Loading
@@ -603,20 +603,20 @@ impl SetIndex!(K, V) for HashMap!(K, V) {
}
}
 
impl Length for HashMap!(K, V) {
impl Length for Map!(K, V) {
## Returns the number of key-value pairs in this map.
##
## # Examples
##
## Using an empty map:
##
## let map = HashMap.new
## let map = Map.new
##
## map.length # => 0
##
## Using a map with one key-value pair:
##
## let mut map = HashMap.new
## let mut map = Map.new
##
## map['name'] = 'Alice'
##
Loading
Loading
Loading
Loading
@@ -41,7 +41,7 @@ def implement(implement_for: Object, to_implement: Trait) -> Trait {
 
# This marks the Trait as implemented by storing the Trait as an attribute,
# with its value set to True. We can not use other data structures such as
# `std::hash_map::HashMap`, since they may not yet exist when this method is
# `std::map::Map`, since they may not yet exist when this method is
# used.
_INKOC.set_attribute(traits, to_implement, True)
 
Loading
Loading
Loading
Loading
@@ -34,7 +34,7 @@ import test::std::test_ffi
import test::std::test_float
import test::std::test_format
import test::std::test_fs
import test::std::test_hash_map
import test::std::test_map
import test::std::test_inspect
import test::std::test_integer
import test::std::test_io
Loading
Loading
import std::format::DefaultFormatter
import std::hash_map::DefaultHasher
import std::map::DefaultHasher
import std::test
import std::test::assert
 
Loading
Loading
import std::float::(NAN, INFINITY, NEGATIVE_INFINITY)
import std::format::DefaultFormatter
import std::hash_map::DefaultHasher
import std::map::DefaultHasher
import std::test
import std::test::assert
 
Loading
Loading
Loading
Loading
@@ -128,12 +128,12 @@ test.group('std::array::Array.inspect') do (g) {
}
}
 
test.group('std::hash_map::HashMap.inspect') do (g) {
g.test('Inspecting an empty HashMap') {
test.group('std::map::Map.inspect') do (g) {
g.test('Inspecting an empty Map') {
assert.equal(%[].inspect, '%[]')
}
 
g.test('Inspecting a non-empty HashMap') {
g.test('Inspecting a non-empty Map') {
assert.equal(%['key': 10].inspect, '%["key": 10]')
}
}
import std::hash_map::DefaultHasher
import std::map::DefaultHasher
import std::test
import std::test::assert
 
Loading
Loading
import std::hash_map::(self, DefaultHasher, Pair, RandomState)
import std::map::(self, DefaultHasher, Pair, RandomState)
import std::test
import std::test::assert
 
test.group('std::hash_map::DefaultHasher.write_integer') do (g) {
test.group('std::map::DefaultHasher.write_integer') do (g) {
g.test('Hashing an Integer') {
let hasher = DefaultHasher.new(1, 2)
 
Loading
Loading
@@ -19,7 +19,7 @@ test.group('std::hash_map::DefaultHasher.write_integer') do (g) {
}
}
 
test.group('std::hash_map::DefaultHasher.write_float') do (g) {
test.group('std::map::DefaultHasher.write_float') do (g) {
g.test('Hashing an Float') {
let hasher = DefaultHasher.new(1, 2)
 
Loading
Loading
@@ -36,7 +36,7 @@ test.group('std::hash_map::DefaultHasher.write_float') do (g) {
}
}
 
test.group('std::hash_map::DefaultHasher.write_string') do (g) {
test.group('std::map::DefaultHasher.write_string') do (g) {
g.test('Hashing a String') {
let hasher = DefaultHasher.new(1, 2)
 
Loading
Loading
@@ -53,7 +53,7 @@ test.group('std::hash_map::DefaultHasher.write_string') do (g) {
}
}
 
test.group('std::hash_map::DefaultHasher.write_boolean') do (g) {
test.group('std::map::DefaultHasher.write_boolean') do (g) {
g.test('Hashing a Boolean') {
let hasher = DefaultHasher.new(1, 2)
 
Loading
Loading
@@ -70,7 +70,7 @@ test.group('std::hash_map::DefaultHasher.write_boolean') do (g) {
}
}
 
test.group('std::hash_map::DefaultHasher.reset') do (g) {
test.group('std::map::DefaultHasher.reset') do (g) {
g.test('Resetting the internal state of a hasher') {
let hasher = DefaultHasher.new(1, 2)
let hash1 = hasher.to_hash
Loading
Loading
@@ -84,7 +84,7 @@ test.group('std::hash_map::DefaultHasher.reset') do (g) {
}
}
 
test.group('std::hash_map::RandomState.to_hasher') do (g) {
test.group('std::map::RandomState.to_hasher') do (g) {
g.test('Creating a DefaultHasher') {
let state = RandomState.new
let hasher1 = state.to_hasher
Loading
Loading
@@ -97,7 +97,7 @@ test.group('std::hash_map::RandomState.to_hasher') do (g) {
}
}
 
test.group('std::hash_map::Pair.distance') do (g) {
test.group('std::map::Pair.distance') do (g) {
g.test('Obtaining the distance of a Pair') {
let pair = Pair.new(key: 'key', value: 'value', hash: 0)
 
Loading
Loading
@@ -105,7 +105,7 @@ test.group('std::hash_map::Pair.distance') do (g) {
}
}
 
test.group('std::hash_map::Pair.replace_with?') do (g) {
test.group('std::map::Pair.replace_with?') do (g) {
g.test('Checking if a Pair should be replaced with another Pair') {
let pair1 = Pair.new(key: 'a', value: 'a', hash: 0)
let pair2 = Pair.new(key: 'b', value: 'b', hash: 0)
Loading
Loading
@@ -117,7 +117,7 @@ test.group('std::hash_map::Pair.replace_with?') do (g) {
}
}
 
test.group('std::hash_map::Pair.reset_distance') do (g) {
test.group('std::map::Pair.reset_distance') do (g) {
g.test('Resetting the distance of a Pair') {
let pair = Pair.new(key: 'key', value: 'value', hash: 0)
 
Loading
Loading
@@ -128,7 +128,7 @@ test.group('std::hash_map::Pair.reset_distance') do (g) {
}
}
 
test.group('std::hash_map::Pair.increase_distance') do (g) {
test.group('std::map::Pair.increase_distance') do (g) {
g.test('Increasing the distance of a Pair') {
let pair = Pair.new(key: 'key', value: 'value', hash: 0)
 
Loading
Loading
@@ -138,7 +138,7 @@ test.group('std::hash_map::Pair.increase_distance') do (g) {
}
}
 
test.group('std::hash_map::Pair.reduce_distance') do (g) {
test.group('std::map::Pair.reduce_distance') do (g) {
g.test('Reducing the distance of a Pair') {
let pair = Pair.new(key: 'key', value: 'value', hash: 0)
 
Loading
Loading
@@ -149,7 +149,7 @@ test.group('std::hash_map::Pair.reduce_distance') do (g) {
}
}
 
test.group('std::hash_map::Pair.key') do (g) {
test.group('std::map::Pair.key') do (g) {
g.test('Obtaining the key of a Pair') {
let pair = Pair.new(key: 'key', value: 'value', hash: 0)
 
Loading
Loading
@@ -157,7 +157,7 @@ test.group('std::hash_map::Pair.key') do (g) {
}
}
 
test.group('std::hash_map::Pair.value') do (g) {
test.group('std::map::Pair.value') do (g) {
g.test('Obtaining the value of a Pair') {
let pair = Pair.new(key: 'key', value: 'value', hash: 0)
 
Loading
Loading
@@ -165,7 +165,7 @@ test.group('std::hash_map::Pair.value') do (g) {
}
}
 
test.group('std::hash_map::Pair.hash') do (g) {
test.group('std::map::Pair.hash') do (g) {
g.test('Obtaining the hash of a Pair') {
let pair = Pair.new('key', 'value', 123)
 
Loading
Loading
@@ -173,9 +173,9 @@ test.group('std::hash_map::Pair.hash') do (g) {
}
}
 
test.group('std::hash_map::HashMap.rehash') do (g) {
g.test('Rehashing an empty HashMap') {
let map = HashMap.new
test.group('std::map::Map.rehash') do (g) {
g.test('Rehashing an empty Map') {
let map = Map.new
 
assert.equal(map.buckets, [])
 
Loading
Loading
@@ -184,8 +184,8 @@ test.group('std::hash_map::HashMap.rehash') do (g) {
assert.equal(map.buckets, [Nil, Nil])
}
 
g.test('Rehashing a HashMap with pairs') {
let map = HashMap.new
g.test('Rehashing a Map with pairs') {
let map = Map.new
let pair1 = Pair.new(key: 'a', value: 'value', hash: 0)
let pair2 = Pair.new(key: 'b', value: 'value', hash: 1)
 
Loading
Loading
@@ -211,9 +211,9 @@ test.group('std::hash_map::HashMap.rehash') do (g) {
}
}
 
test.group('std::hash_map::HashMap._insert_pair') do (g) {
g.test('Inserting a Pair into a HashMap') {
let map = HashMap.new
test.group('std::map::Map._insert_pair') do (g) {
g.test('Inserting a Pair into a Map') {
let map = Map.new
let pair = Pair.new(key: 'key', value: 'value', hash: 0)
 
map._insert_pair(pair)
Loading
Loading
@@ -222,8 +222,8 @@ test.group('std::hash_map::HashMap._insert_pair') do (g) {
assert.equal(map.buckets[0], pair)
}
 
g.test('Inserting a Pair into an existing bucket in a HashMap') {
let map = HashMap.new
g.test('Inserting a Pair into an existing bucket in a Map') {
let map = Map.new
let pair1 = Pair.new(key: 'a', value: 'a', hash: 0)
let pair2 = Pair.new(key: 'b', value: 'b', hash: 0)
 
Loading
Loading
@@ -239,7 +239,7 @@ test.group('std::hash_map::HashMap._insert_pair') do (g) {
}
 
g.test('Inserting a Pair using an already used key') {
let map = HashMap.new
let map = Map.new
let pair1 = Pair.new(key: 'a', value: 'a', hash: 0)
let pair2 = Pair.new(key: 'a', value: 'b', hash: 0)
 
Loading
Loading
@@ -251,7 +251,7 @@ test.group('std::hash_map::HashMap._insert_pair') do (g) {
}
 
g.test('Inserting a Pair after an unused bucket') {
let map = HashMap.new
let map = Map.new
let pair1 = Pair.new(key: 'one', value: 1, hash: 4764096362064740795)
let pair2 = Pair.new(key: 'two', value: 2, hash: -9161411174267222279)
let pair3 = Pair.new(key: 'three', value: 3, hash: 902578265635837404)
Loading
Loading
@@ -271,22 +271,22 @@ test.group('std::hash_map::HashMap._insert_pair') do (g) {
}
}
 
test.group('std::hash_map::HashMap.remove') do (g) {
g.test('Removing an existing key from a HashMap') {
test.group('std::map::Map.remove') do (g) {
g.test('Removing an existing key from a Map') {
let map = %['a': 'b']
 
assert.equal(map.remove('a'), 'b')
assert.equal(map.buckets[0], Nil)
}
 
g.test('Removing a non-existing key from a HashMap') {
let map: HashMap!(String, String) = HashMap.new
g.test('Removing a non-existing key from a Map') {
let map: Map!(String, String) = Map.new
 
assert.equal(map.remove('a'), Nil)
}
 
g.test('Backwards shifting Pairs that follow the removed Pair') {
let map = HashMap.new
let map = Map.new
let pair1 = Pair.new(key: 'a', value: 'a', hash: 0)
let pair2 = Pair.new(key: 'b', value: 'b', hash: 0)
 
Loading
Loading
@@ -300,13 +300,13 @@ test.group('std::hash_map::HashMap.remove') do (g) {
}
}
 
test.group('HashMap literals') do (g) {
g.test('Creating an empty HashMap') {
assert.equal(%[], HashMap.new)
test.group('Map literals') do (g) {
g.test('Creating an empty Map') {
assert.equal(%[], Map.new)
}
 
g.test('Creating a HashMap with keys and values') {
let expected = HashMap.new
g.test('Creating a Map with keys and values') {
let expected = Map.new
 
expected['name'] = 'Alice'
expected['city'] = 'Amsterdam'
Loading
Loading
@@ -315,36 +315,36 @@ test.group('HashMap literals') do (g) {
}
}
 
test.group('std::hash_map::HashMap.from_array') do (g) {
g.test('Creating a HashMap without any keys and values') {
let map = HashMap.from_array([], [])
test.group('std::map::Map.from_array') do (g) {
g.test('Creating a Map without any keys and values') {
let map = Map.from_array([], [])
 
assert.equal(map, %[])
}
 
g.test('Creating a HashMap with keys but without values') {
g.test('Creating a Map with keys but without values') {
assert.panic {
HashMap.from_array(['name'], [])
Map.from_array(['name'], [])
}
}
 
g.test('Creating a HashMap with an equal number of keys and values') {
let map = HashMap.from_array(['name', 'city'], ['Alice', 'Amsterdam'])
g.test('Creating a Map with an equal number of keys and values') {
let map = Map.from_array(['name', 'city'], ['Alice', 'Amsterdam'])
 
assert.equal(map['name'], 'Alice')
assert.equal(map['city'], 'Amsterdam')
}
}
 
test.group('std::hash_map::HashMap.empty?') do (g) {
g.test('Checking if a HashMap is empty') {
test.group('std::map::Map.empty?') do (g) {
g.test('Checking if a Map is empty') {
assert.true(%[].empty?)
assert.false(%['a': 'b'].empty?)
}
}
 
test.group('std::hash_map::HashMap.each') do (g) {
g.test('Iterating over the key-value pairs of an empty HashMap') {
test.group('std::map::Map.each') do (g) {
g.test('Iterating over the key-value pairs of an empty Map') {
let mut iters = 0
 
%[].each do (_, _) {
Loading
Loading
@@ -354,7 +354,7 @@ test.group('std::hash_map::HashMap.each') do (g) {
assert.equal(iters, 0)
}
 
g.test('Iterating over the key-value pairs of a non-empty HashMap') {
g.test('Iterating over the key-value pairs of a non-empty Map') {
let mut key_total = 0
let mut val_total = 0
 
Loading
Loading
@@ -368,8 +368,8 @@ test.group('std::hash_map::HashMap.each') do (g) {
}
}
 
test.group('std::hash_map::HashMap.iter') do (g) {
g.test('Creating an Iterator for an empty HashMap') {
test.group('std::map::Map.iter') do (g) {
g.test('Creating an Iterator for an empty Map') {
let map = %[]
let iter = map.iter
 
Loading
Loading
@@ -377,7 +377,7 @@ test.group('std::hash_map::HashMap.iter') do (g) {
assert.equal(iter.next, Nil)
}
 
g.test('Creating an Iterator for a HashMap with key-value pairs') {
g.test('Creating an Iterator for a Map with key-value pairs') {
let map = %['name': 'Alice']
let iter = map.iter
 
Loading
Loading
@@ -390,16 +390,16 @@ test.group('std::hash_map::HashMap.iter') do (g) {
}
}
 
test.group('std::hash_map::HashMap.keys') do (g) {
g.test('Creating a Keys Iterator for an empty HashMap') {
let map: HashMap!(String, String) = %[]
test.group('std::map::Map.keys') do (g) {
g.test('Creating a Keys Iterator for an empty Map') {
let map: Map!(String, String) = %[]
let iter = map.keys
 
assert.false(iter.next?)
assert.equal(iter.next, Nil)
}
 
g.test('Creating a Keys Iterator for a HashMap with key-value pairs') {
g.test('Creating a Keys Iterator for a Map with key-value pairs') {
let map = %['name': 'Alice']
let iter = map.keys
 
Loading
Loading
@@ -409,16 +409,16 @@ test.group('std::hash_map::HashMap.keys') do (g) {
}
}
 
test.group('std::hash_map::HashMap.values') do (g) {
g.test('Creating a Values Iterator for an empty HashMap') {
let map: HashMap!(String, String) = %[]
test.group('std::map::Map.values') do (g) {
g.test('Creating a Values Iterator for an empty Map') {
let map: Map!(String, String) = %[]
let iter = map.values
 
assert.false(iter.next?)
assert.equal(iter.next, Nil)
}
 
g.test('Creating a Values Iterator for a HashMap with key-value pairs') {
g.test('Creating a Values Iterator for a Map with key-value pairs') {
let map = %['name': 'Alice']
let iter = map.values
 
Loading
Loading
@@ -428,19 +428,19 @@ test.group('std::hash_map::HashMap.values') do (g) {
}
}
 
test.group('std::hash_map::HashMap.==') do (g) {
g.test('Comparing two identical HashMap instances') {
test.group('std::map::Map.==') do (g) {
g.test('Comparing two identical Map instances') {
assert.equal(%['name': 'Alice'], %['name': 'Alice'])
}
 
g.test('Comparing two different HashMap instances') {
g.test('Comparing two different Map instances') {
assert.not_equal(%[], %['name': 'Alice'])
assert.not_equal(%['foo': 'bar'], %['name': 'Alice'])
}
}
 
test.group('std::hash_map::HashMap.key?') do (g) {
g.test('Checking if a HashMap defines a key') {
test.group('std::map::Map.key?') do (g) {
g.test('Checking if a Map defines a key') {
let map = %['name': 'Alice']
 
assert.true(map.key?('name'))
Loading
Loading
@@ -448,7 +448,7 @@ test.group('std::hash_map::HashMap.key?') do (g) {
}
}
 
test.group('std::hash_map::HashMap.[]') do (g) {
test.group('std::map::Map.[]') do (g) {
g.test('Obtaining the value of a non-existing key') {
let map = %['name': 'Alice']
 
Loading
Loading
@@ -462,7 +462,7 @@ test.group('std::hash_map::HashMap.[]') do (g) {
}
}
 
test.group('std::hash_map::HashMap.[]=') do (g) {
test.group('std::map::Map.[]=') do (g) {
g.test('Setting the value of a non-existing key') {
let map = %['name': 'Alice']
 
Loading
Loading
@@ -478,12 +478,12 @@ test.group('std::hash_map::HashMap.[]=') do (g) {
}
}
 
test.group('std::hash_map::HashMap.length') do (g) {
g.test('Obtaining the length of an empty HashMap') {
test.group('std::map::Map.length') do (g) {
g.test('Obtaining the length of an empty Map') {
assert.equal(%[].length, 0)
}
 
g.test('Obtaining the length of a HashMap with key-value pairs') {
g.test('Obtaining the length of a Map with key-value pairs') {
assert.equal(%['name': 'Alice'].length, 1)
assert.equal(%['name': 'Alice', 'city': 'Amsterdam'].length, 2)
}
Loading
Loading
import std::fs::path::Path
import std::hash_map::DefaultHasher
import std::map::DefaultHasher
import std::test
import std::test::assert
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment