Skip to content

Dict

Parameters

[Key = Dynamic, Value = Dynamic, Hasher = MurMur3Hasher] 

Implements an ordered dictionary backed by a Hashtable using the provided hasher. The order of insertion of items is preserved and items can be iterated bidirectionally from the beginning to the end and vice versa.

graph BT
N1["Dict[Key,Value,Hasher]"] -->|inherits| N2["ReverseIterable[Key,Value]"];
N1["Dict[Key,Value,Hasher]"] -->|inherits| N3["Unpackable[Key,Value]"];

Characteristics

Quality Value
Inherits ReverseIterable[Key, Value], Unpackable[Key, Value]
Extends N/A
Decorators #sealed;
Is enum false
Is sealed true
Is extern false

Type Aliases

DType

DType = Key, Value

ListData

ListData = Pair[Hasher.HashValueType, Pair[Key, Value]]

Subscript

[s Self, key @Key] -> @Value

access the value represented by the provided key. If the key does not exist when getting the value an instance of WrongArgumentException will be raised. If the key does exist when setting a value the old value will be overridden with the new one.

Methods

construct

construct (s Self, size_hint Len = 0) -> Self
constructs a new dictionary. If size_hint > 0 will help plan for the correct amount of memory beforehand


init

init (s Self, size_hint Len = 0) -> Nil

get_iterator

get_iterator (s Self) -> DictIterator[Self]

get_reverse_iterator

get_reverse_iterator (s Self) -> DictIterator[Self]

len

#strict
#Gambol.function.alwaysinline
len (s Self) -> Len
returns the number of items in this dictionary.


copy

copy (s Self) -> strictly SelfType
create a new dictionary with the same key-value pairs as this one


keys

keys (s Self) -> List[Key]
will return a list containing all the keys added to this dictionary in the same insertion order


values

values (s Self) -> List[Value]
will return a list containing all the values added to this dictionary in the same insertion order


get_value_ptr

get_value_ptr (s Self, key Key) -> PointerToVariable[Value]
get a pointer to the value specified by key. If the key does not exist will raise an instance of WrongArgumentException.


add

add (s Self, key @Key, value @Value) -> Nil
adds a key-value pair to the the dictionary. if the key already exists the old value will be overridden with the new one


remove

remove (s Self, key @Key) -> Nil
removes the key-value pair from the dictionary if the key exists


first

first (s Self) -> @DType?
returns the first key-value pair added to the dictionary


last

last (s Self) -> @DType?
returns the last key-value pair added to the dictionary


pop

pop (s Self) -> @DType?
returns and removes the last key-value pair added to the dictionary


str

str (s Self, delimiter: String = `, `, pair_delimiter: String = `: `, quote_begin: String = ```, quote_end: String = ```, enclose_begin: String = `[`, enclose_end: String = `]`) -> String

__erase

__erase (s Self, index Len, list_ptr Pointer) -> Nil

__calculate_index

#Gambol.function.alwaysinline
__calculate_index (s Self, hash_value Hasher.HashValueType) -> Len

__grow_if_necessary

__grow_if_necessary (s Self) -> Nil

Binary Operators

is in

is in (s Self, key @Key) -> Bool
check if a key exists in the dictionary


==

== (s Self, o Self) -> Bool
equality is defined as having the same set of keys in both dictionaries with the associated values for each key in both dictionaries also being equal


<=

<= (s Self, o Self) -> Bool
returns whether this dictionary is a subset of o. In order to be a subset all keys in this dictionary must also exist in o and the associated values for each key must be equal in both dictinoaries.


<

< (s Self, o Self) -> Bool
returns whether this dictionary is a proper subset of o.


>=

>= (s Self, o Self) -> Bool
returns whether o is a subset of this dictionary.


>

> (s Self, o Self) -> Bool
returns whether o is a proper subset of this dictionary.


|

| (s Self, o Self) -> strictly SelfType
returns a new dictionary representing the union of this dictionary and o. If a key exists in both dictionaries but the values are different the value from o will be selected.


|=

|= (s Self, o Self) -> Self
adds all the key value pairs in o to this dictionary. If a key already exists in this dictionary then the original value is overridden with the new one.


&

& (s Self, o Self) -> strictly SelfType
creates a new dictionary representing an insersection of this dictionary and o with equality being defined as both the key and the value being equal


&=

&= (s Self, o Self) -> Self
removes all key value pairs in this dictionary for which either the key does not exist in o or if it does the associated value is different


-

- (s Self, o Self) -> SelfType
will return a new dictionary that is the same as this dictionary with all key value pairs that also exist in o removed


-=

-= (s Self, o Self) -> Self
will remove all key value pairs from this dictionary that also exist in o.


^

^ (s Self, o Self) -> SelfType
will return a new dictionary representing the symmetric difference between this dictionary and o with equality being defined as both the key and the value being equal.


^=

^= (s Self, o Self) -> Self
will convert this dictionary to the symmetric difference between this dictionary and o with equality being defined as both the key and the value being equal.


Properties

kInitSize

const global kInitSize Len = 64

kGrowthFactor

const global kGrowthFactor Len = 3

__table

__table List[Pointer](kInitSize)

__len

__len Len

__load

__load Len

__first_ptr

__first_ptr Pointer

__last_ptr

__last_ptr Pointer