1  package frost.collections
 2  
 3  ====================================================================================================
 4  A read-only view of the standard "Map" abstract data type, which stores key/value pairs such that no
 5  key appears more than once in the collection. Given a key, a `MapView` will return the corresponding
 6  value, and generally does so very quickly (constant or `log n` time, depending on the
 7  implementation).
 8  ====================================================================================================
 9  interface MapView<K, V> {
10      ================================================================================================
11      The number of key/value pairs the map contains.
12      ================================================================================================
13      property count:Int
14  
15      ================================================================================================
16      An iterator which returns all of the keys in the map.
17      ================================================================================================
18      property keys:Iterator<K>
19  
20      ================================================================================================
21      An iterator which returns all of the values in the map. Because multiple keys may map to the
22      same value, this iterator may return duplicate values.
23      ================================================================================================
24      property values:Iterator<V>
25  
26      ================================================================================================
27      An iterator which returns all of the (key, value) pairs in the map.
28      ================================================================================================
29      property entries:Iterator<(K, V)>
30  
31      function get_count():Int
32  
33      ================================================================================================
34      Returns the value mapped to the given key, or `null` if no such mapping exists. If the map's
35      type permits `null` values, this function does not distinguish between cases where the map does
36      not contain the given key, and cases where it does contain the key, but it maps to `null`. The
37      `contains` method can be used to disambiguate this situation.
38      ================================================================================================
39      function [](key:K):V?
40  
41      ================================================================================================
42      Returns `true` if the map contains the given key (even if the value it maps to is `null`)
43      ================================================================================================
44      function contains(key:K):Bit
45  
46      function get_entries():Iterator<(K, V)>
47  
48      @default
49      function get_keys():Iterator<K> {
50          return entries.map(e => e[0])
51      }
52  
53      @default
54      function get_values():Iterator<V> {
55          return entries.map(e => e[1])
56      }
57  }