Interface

interface EquatableCollection<T> where T <: Equatable<T>

public interface EquatableCollection<T> <: Collection<T> where T <: Equatable<T> {
    func contains(element: T): Bool
    func containsAll(elements: Collection<T>): Bool
}

Description: Defines the types of collections that support the comparison operation.

Parent Type:

func contains(T)

func contains(element: T): Bool

Description: Checks whether keys contain a specified element.

Parameters:

  • element: T: specified element, which is to be determined whether keys contain the element.

Returns:

  • Bool: If the element is contained, true is returned. Otherwise, false is returned.

func containsAll(Collection<T>)

func containsAll(elements: Collection<T>): Bool

Description: Checks whether keys contain all elements of a specified collection.

Parameters:

  • elements: Collection<T>: collection to be checked

Returns:

  • Bool: If all elements are contained, true is returned. Otherwise, false is returned.

interface Map<K, V> where K <: Equatable<K>

Description: Provides a method of mapping keys to values. The method supports using keys to find values, so it can be used to store and operate key-value pairs.

map cannot contain duplicate keys. Each key can be mapped to only one value.

public interface Map<K, V> <: Collection<(K, V)> where K <: Equatable<K> {
    func get(key: K): Option<V>
    func contains(key: K): Bool
    func containsAll(keys: Collection<K>): Bool
    mut func put(key: K, value: V): Option<V>
    mut func putAll(elements: Collection<(K, V)>): Unit
    mut func remove(key: K): Option<V>
    mut func removeAll(keys: Collection<K>): Unit
    mut func removeIf(predicate: (K, V) -> Bool): Unit
    mut func clear(): Unit
    func clone(): Map<K, V>
    operator func [](key: K): V
    operator func [](key: K, value!: V): Unit
    func keys(): EquatableCollection<K>
    func values(): Collection<V>
    prop size: Int64
    func isEmpty(): Bool
    func iterator(): Iterator<(K, V)>
}

Parent Type:

prop size

prop size: Int64

Description: Returns the number of all key-value pairs in a Map instance.

Type: Int64

func clear()

mut func clear(): Unit

Description: Clears all key-value pairs.

func clone()

func clone(): Map<K, V>

Description: Clones a Map instance.

Returns:

  • Map < K, V >: Map<K, V> instance

func contains(K)

func contains(key: K): Bool

Description: Checks whether the mapping of a specified key is included.

Parameters:

  • key: K: key to be checked

Returns:

  • Bool: If the mapping is included, true is returned. Otherwise, false is returned.

func containsAll(Collection<K>)

func containsAll(keys: Collection<K>): Bool

Description: Checks whether the mappings of keys of a specified collection are included.

Parameters:

  • keys: Collection<K>: collection of keys to be checked

Returns:

  • Bool: If the mappings are included, true is returned. Otherwise, false is returned.

func get(K)

func get(key: K): Option<V>

Description: Obtains the mapping value in a Map instance according to key.

Parameters:

  • key: K: key used to obtain a value

Returns:

func isEmpty()

func isEmpty(): Bool

Description: Checks whether a Map instance is empty.

Returns:

  • Bool: If the Map instance is empty, true is returned. Otherwise, false is returned.

func iterator()

func iterator(): Iterator<(K, V)>

Description: Returns the iterator of a Map instance.

Returns:

func keys()

func keys(): EquatableCollection<K>

Description: Returns all keys in a Map instance and stores them in an EquatableCollection<K> container.

Returns:

func put(K, V)

mut func put(key: K, value: V): Option<V>

Description: Puts a passed key-value pair into a Map instance. For an existing key in a Map instance that is the same as the new key to be passed, the value mapped to the key is replaced with the new value.

Parameters:

  • key: K: key to be put
  • value: V: value to be allocated

Returns:

  • Option<V>: If key exists before value allocation, the old value corresponding to key is encapsulated with Option. Otherwise, Option<V>.None is returned.

func putAll(Collection<(K, V)>)

mut func putAll(elements: Collection<(K, V)>): Unit

Description: Puts new key-value pairs into a Map instance. For an existing key in a Map instance that is the same as the new key to be passed, the value mapped to the key is replaced with the new value.

Parameters:

  • elements: Collection<(K, V)>: collection of key-value pairs to be put into the Map instance

func remove(K)

mut func remove(key: K): Option<V>

Description: Deletes the mapping (if any) of the specified key from a Map instance.

Parameters:

  • key: K: key to be deleted

Returns:

  • Option<V>: value corresponding to the key to be removed from the Map instance, which is encapsulated by Option

func removeAll(Collection<K>)

mut func removeAll(keys: Collection<K>): Unit

Description: Deletes the mapping (if any) of a specified collection from a mapping.

Parameters:

func removeIf((K, V) -> Bool)

mut func removeIf(predicate: (K, V) -> Bool): Unit

Description: Passes a lambda expression. If the conditions are met, the corresponding key-value pair is deleted.

Parameters:

  • predicate: (K, V) ->Bool: lambda expression used for judgment

func values()

func values(): Collection<V>

Description: Returns all values in a Map instance and stores them in a Collection<V> container.

Returns:

operator func [](K)

operator func [](key: K): V

Description: Overrides the indexing operator. If key exists, the value corresponding to key is returned. If key does not exist, an exception is thrown.

Parameters:

  • key: K: key to be searched for

Returns:

  • V: value corresponding to key

operator func [](K, V)

operator func [](key: K, value!: V): Unit

Description: Overrides the indexing operator. If key exists, the new value overwrites the old value. If key does not exist, the key-value pair is added.

Parameters:

  • key: K: key to be set
  • value!: V: value to be set

interface Set<T> where T <: Equatable<T>

public interface Set<T> <: Collection<T> where T <: Equatable<T> {
    func contains(element: T): Bool
    func subsetOf(other: Set<T>): Bool
    func containsAll(elements: Collection<T>): Bool
    mut func put(element: T): Bool
    mut func putAll(elements: Collection<T>): Unit
    mut func remove(element: T): Bool
    mut func removeAll(elements: Collection<T>): Unit
    mut func removeIf(predicate: (T) -> Bool): Unit
    mut func clear(): Unit
    mut func retainAll(elements: Set<T>): Unit
    func clone(): Set<T>
}

Description: Specifies the collection without duplicate elements.

The Set interface does not specify the internal implementation mode. In an instance of the Set interface, the internal elements are usually unordered and cannot be accessed through indexes. In addition, the element insertion order cannot be ensured.

Parent Type:

func clear()

mut func clear(): Unit

Description: Clears all key-value pairs.

func clone()

func clone(): Set<T>

Description: Clones a Set instance and returns a new Set instance.

Returns:

func contains(T)

func contains(element: T): Bool

Description: Returns true if a collection contains a specified element.

Parameters:

  • element: T: element to be checked

Returns:

  • Bool: If the specified element is contained, true is returned. Otherwise, false is returned.

func containsAll(Collection<T>)

func containsAll(elements: Collection<T>): Bool

Description: Checks whether a collection contains a specified collection.

Parameters:

Returns:

  • Bool: If the collection contains the specified collection, true is returned. Otherwise, false is returned.

func put(T)

mut func put(element: T): Bool

Description: Adds an element. If the element already exists, it is not added.

Parameters:

  • element: T: element to be added

Returns:

  • Bool: If the element is added successfully, true is returned. Otherwise, false is returned.

func putAll(Collection<T>)

mut func putAll(elements: Collection<T>): Unit

Description: Adds all elements in a Collection instance to a Set instance. If elements to be added already exist in the HashSet instance, they are not added.

Parameters:

  • elements: Collection<T>: collection of elements to be added

func remove(T)

mut func remove(element: T): Bool

Description: Removes a specified element (if any) from a collection.

Parameters:

  • element: T: element to be deleted

Returns:

  • Bool: If the specified element exists in the collection and is deleted successfully, true is returned. Otherwise, false is returned.

func removeAll(Collection<T>)

mut func removeAll(elements: Collection<T>): Unit

Description: Removes all elements that are contained in a specified Collection instance from a Set instance.

Parameters:

func removeIf((T) -> Bool)

mut func removeIf(predicate: (T) -> Bool): Unit

Description: Passes a lambda expression. If the condition of predicate is met, the corresponding element is deleted.

Parameters:

  • predicate: (T) ->Bool: lambda expression used for judgment

func retainAll(Set<T>)

mut func retainAll(elements: Set<T>): Unit

Description: Retains only the elements in a Set instance that are the same as those in elements.

Parameters:

  • elements: Set<T>: set of elements to be stored

func subsetOf(Set<T>)

func subsetOf(other: Set<T>): Bool

Description: Checks whether a set is a subset of other.

Parameters:

  • other: Set<T>: another set

Returns:

  • Bool: If the set is a subset of the specified set, true is returned. Otherwise, false is returned.