Class

class ArrayList<T>

public class ArrayList<T> <: Collection<T> {
    public init()
    public init(capacity: Int64)
    public init(size: Int64, initElement: (Int64) -> T)
    public init(elements: Array<T>)
    public init(elements: Collection<T>)
}

Description: Provides variable-length arrays.

ArrayList is a linear dynamic array. Different from Array, ArrayList has a size that can be automatically adjusted as required and does not need to be specified during creation.

Note:

  • When an element is added to a dynamic array, if the array is full, a larger memory space is reallocated, and original elements are copied to the new memory space.
  • The advantage of dynamic arrays is that they can reduce memory usage and can be automatically resized as required. Therefore, dynamic arrays are suitable for scenarios where elements need to be frequently added or deleted. However, the disadvantage of dynamic arrays is that performance may deteriorate when memory space is reallocated. Therefore, performance needs to be considered when dynamic arrays are used.

Parent Type:

prop size

public prop size: Int64

Description: Returns the number of elements in an ArrayList instance.

Type: Int64

init()

public init()

Description: Constructs an ArrayList instance whose initial capacity is the default value 16.

init(Array<T>)

public init(elements: Array<T>)

Description: Constructs an ArrayList instance that contains all elements in a specified array.

Note:

When the type of T is Int64, the syntax sugar version of the variable-length parameter of this constructor may be ambiguous with public init(Int64). For example, ArrayList<Int64>(8, 9) represents constructing an ArrayList instance containing two elements, and ArrayList<Int64>(8) represents constructing an ArrayList instance whose capacity is 8.

Parameters:

  • elements: Array<T>: passed array

init(Collection<T>)

public init(elements: Collection<T>)

Description: Constructs an ArrayList instance that contains all elements in a specified collection. These elements are arranged in the order returned from the iterator of the collection.

Parameters:

init(Int64)

public init(capacity: Int64)

Description: Constructs an ArrayList instance with initial capacity of a specified size.

Parameters:

  • capacity: Int64: specified initial capacity

Throws:

init(Int64, (Int64) -> T)

public init(size: Int64, initElement: (Int64) -> T)

Description: Constructs an ArrayList instance with a specified initial element quantity and a specified rule function. This constructor sets the capacity of ArrayList based on the size parameter.

Parameters:

  • size: Int64: initial function element quantity
  • initElement: (Int64) ->T: passed initialization function

Throws:

func append(T)

public func append(element: T): Unit

Description: Adds a specified element to the end of an ArrayList instance.

Parameters:

  • element: T: inserted element; type: T

Example:

For details, see [append and insert functions of ArrayList] (../collection_package_samples/sample_arraylist_append_insert.md).

func appendAll(Collection<T>)

public func appendAll(elements: Collection<T>): Unit

Description: Adds all elements in a specified collection to the end of an ArrayList instance.

This function traverses the collection in the input parameter in the iterator order and inserts all elements to the end of the ArrayList instance.

Parameters:

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

func capacity()

public func capacity(): Int64

Description: Returns the capacity of an ArrayList instance.

Returns:

func clear()

public func clear(): Unit

Description: Deletes all elements in an ArrayList instance.

Example:

For details, see [remove, clear, and slice functions of ArrayList] (../collection_package_samples/sample_arraylist_remove_clear_slice.md).

func clone()

public func clone(): ArrayList<T>

Description: Returns a copy (shallow copy) of an ArrayList instance.

Returns:

func get(Int64)

public func get(index: Int64): ?T

Description: Returns the element at a specified location in an ArrayList instance.

Parameters:

  • index: Int64: index of the element to be returned

Returns:

  • ?T: element at the specified location. If index is less than 0 or greater than or equal to the number of elements in the ArrayList instance, None is returned.

Example:

For details, see [get and set functions of ArrayList] (../collection_package_samples/sample_arraylist_get_set.md).

func getRawArray()

public unsafe func getRawArray(): Array<T>

Description: Returns the raw data of an ArrayList instance.

Note:

This is an unsafe interface, which must be used in the unsafe context.

Raw data refers to an array implemented at the bottom layer of ArrayList. Its size is greater than or equal to the number of elements in ArrayList, and its locations where indexes are greater than or equal to the size of ArrayList may contain uninitialized elements. Accessing the locations may cause undefined behavior.

Returns:

func insert(Int64, T)

public func insert(index: Int64, element: T): Unit

Description: Inserts a specified element to a specified location in an ArrayList instance.

Parameters:

  • index: Int64: target index of the element to be inserted
  • element: T: T-type element to be inserted

Throws:

Example:

For details, see [append and insert functions of ArrayList] (../collection_package_samples/sample_arraylist_append_insert.md).

func insertAll(Int64, Collection<T>)

public func insertAll(index: Int64, elements: Collection<T>): Unit

Description: Inserts all elements in a specified collection from a specified location into an ArrayList instance.

This function traverses the collection in the input parameter in the iterator order and inserts all elements to the specified location.

Parameters:

  • index: Int64: target index of the collection to be inserted
  • elements: Collection<T>: T-type element collection to be inserted

Throws:

Example:

For details, see [remove, clear, and slice functions of ArrayList] (../collection_package_samples/sample_arraylist_remove_clear_slice.md).

func isEmpty()

public func isEmpty(): Bool

Description: Checks whether an ArrayList instance is empty.

Returns:

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

func iterator()

public func iterator(): Iterator<T>

Description: Returns the iterator of elements in an ArrayList instance.

Returns:

func prepend(T)

public func prepend(element: T): Unit

Description: Inserts a specified element into an ArrayList instance at the start location.

Parameters:

  • element: T: T-type element to be inserted

func prependAll(Collection<T>)

public func prependAll(elements: Collection<T>): Unit

Description: Inserts all elements in a specified collection from the start location into an ArrayList instance.

This function traverses the collection in the input parameter in the iterator order and inserts all elements to the specified location.

Parameters:

  • elements: Collection<T>: T-type element collection to be inserted

func remove(Int64)

public func remove(index: Int64): T

Description: Deletes the element at a specified location in an ArrayList instance.

Parameters:

  • index: Int64: index of the element to be deleted

Returns:

  • T: deleted element

Throws:

Example:

For details, see [remove, clear, and slice functions of ArrayList] (../collection_package_samples/sample_arraylist_remove_clear_slice.md).

func remove(Range<Int64>)

public func remove(range: Range<Int64>): Unit

Description: Deletes all elements contained in the Range range of an ArrayList instance.

Note:

If the range parameter is a Range instance constructed using the constructor of Range and hasEnd is false, the value of end does not take effect and is not affected by the value of isClosed passed during construction. The last element of the original array is included.

Parameters:

  • range: Range<Int64>: range of elements to be deleted

Throws:

func removeIf((T) -> Bool)

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

Description: Deletes all elements that meet a specified lambda expression or function from an ArrayList instance.

Parameters:

  • predicate: (T) ->Bool: condition used for determining deletion

func reserve(Int64)

public func reserve(additional: Int64): Unit

Description: Increases the capacity of an ArrayList instance.

Expands the capacity of ArrayList by additional. When additional is less than or equal to 0, capacity is not expanded. When the remaining capacity of ArrayList is greater than or equal to the additional capacity, capacity is not expanded. When the remaining capacity of ArrayList is less than the additional capacity, capacity is expanded to the larger value of (1.5 times the rounded-down original capacity) and (additional + used capacity).

Parameters:

  • additional: Int64: size to which capacity is expanded

Throws:

  • OverflowException: If the sum of additional capacity and used capacity exceeds Int64.Max, this exception is thrown.

func reverse()

public func reverse(): Unit

Description: Reverses the order of elements in an ArrayList instance.

func set(Int64, T)

public func set(index: Int64, element: T): Unit

Description: Replaces the element at the specified location in an ArrayList instance with a specified element.

Parameters:

  • index: Int64: index to be set
  • element: T: T-type element

Throws:

Example:

For details, see [get and set functions of ArrayList] (../collection_package_samples/sample_arraylist_get_set.md).

func slice(Range<Int64>)

public func slice(range: Range<Int64>): ArrayList<T>

Description: Returns the ArrayList<T> corresponding to the passed parameter range index.

Note:

If the range parameter is a Range instance constructed using the constructor of Range, the behaviors are as follows:

  1. The value of start is the value passed to the constructor and is not affected by the value of hasStart passed in during construction.
  2. When hasEnd is false, the value of end does not take effect and is not affected by the value of isClosed passed in during construction, and the last element of the original array is included.

Parameters:

Returns:

Throws:

Example:

For details, see [remove, clear, and slice functions of ArrayList] (../collection_package_samples/sample_arraylist_remove_clear_slice.md).

func sortBy(Bool, (T, T) -> Ordering)

public func sortBy(stable!: Bool = false, comparator!: (T, T) -> Ordering): Unit

Description: Sorts elements in an array.

The passed comparison function comparator: (t1: T, t2: T) -> Ordering can be used to sort an array based on the return value of the Ordering type. If the return value of comparator is Ordering.GT, t1 is after t2 after sorting. If the return value of comparator is Ordering.LT, t1 is before t2 after sorting. If the return value of comparator is Ordering.EQ and the sorting is stable, t1 is before t2. If the return value of comparator is Ordering.EQ and the sorting is unstable, the order of t1 and t2 is uncertain.

Parameters:

  • stable!: Bool: whether to use stable sorting
  • comparator!: (T, T) ->Ordering: (T, T) -> Ordering type

func toArray()

public func toArray(): Array<T>

Description: Returns an array that contains all elements in the correct order in a list.

Returns:

operator func [](Int64)

public operator func [](index: Int64): T

Description: Overrides the get method.

Parameters:

  • index: Int64: index of the get API

Returns:

  • T: value of the element at the location specified by the index

Throws:

operator func [](Int64, T)

public operator func [](index: Int64, value!: T): Unit

Description: Overrides the set method, that is, replaces the element at the specified location in a list with the specified element using an index operator.

Parameters:

  • index: Int64: index to be set
  • value!: T: T-type value to be set

Throws:

operator func [](Range<Int64>)

public operator func [](range: Range<Int64>): ArrayList<T>

Description: Overrides the slice method.

Note:

  • If the range parameter is a Range instance constructed using the constructor of Range, the behaviors are as follows:

    • The value of start is the value passed to the constructor and is not affected by the value of hasStart passed in during construction.
    • When hasEnd is false, the value of end does not take effect and is not affected by the value of isClosed passed in during construction, and the last element of the original array is included.
  • The ArrayList object returned by the slice operation is a new object and has no reference relationship with the original ArrayList object.

Parameters:

Returns:

Throws:

extend<T> ArrayList<T> <: Equatable<ArrayList<T>> where T <: Equatable<T>

extend<T> ArrayList<T> <: Equatable<ArrayList<T>> where T <: Equatable<T>

Description: Extends the Equatable<ArrayList<T>> interface for the ArrayList<T> type to support the equality check operation.

Parent Type:

operator func ==(ArrayList<T>)

public operator func ==(that: ArrayList<T>): Bool

Description: Checks whether the current instance is equal to the ArrayList instance specified by the that parameter.

Two arrays being equal means that elements at corresponding locations of the two arrays are respectively equal.

Parameters:

  • that: ArrayList<T>: instance to be compared with

Returns:

  • Bool: If the two instances are equal, true is returned. Otherwise, false is returned.

operator func !=(ArrayList<T>)

public operator func !=(that: ArrayList<T>): Bool

Description: Checks whether the current instance is not equal to the ArrayList instance specified by the that parameter.

Parameters:

  • that: ArrayList<T>: instance to be compared with

Returns:

  • Bool: If the two instances are not equal, true is returned. Otherwise, false is returned.

func contains(T)

public func contains(element: T): Bool

Description: Checks whether the current array contains the specified element element.

Parameters:

  • element: T: element to be searched for

Returns:

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

extend<T> ArrayList<T> <: SortExtension where T <: Comparable<T>

extend<T> ArrayList<T> <: SortExtension where T <: Comparable<T>

Description: Extends the SortExtension interface for ArrayList<T> to support array sorting.

Parent Type:

func sort(Bool)

public func sort(stable!: Bool = false): Unit

Description: Sorts elements in the current array in ascending order.

Parameters:

  • stable!: Bool: whether to use stable sorting

func sortDescending(Bool)

public func sortDescending(stable!: Bool = false): Unit

Description: Sorts elements in the current array in descending order.

Parameters:

  • stable!: Bool: whether to use stable sorting

extend<T> ArrayList<T> <: ToString where T <: ToString

extend<T> ArrayList<T> <: ToString where T <: ToString

Description: Extends the ToString interface for ArrayList<T> to support string conversion.

Parent Type:

func toString()

public func toString(): String

Description: Converts the current array to a string.

The string contains the string representation of each element in the array, for example, "[elem1, elem2, elem3]".

Returns:

  • String: string after conversion

class ArrayListIterator<T>

public class ArrayListIterator<T> <: Iterator<T> {
    public init(data: ArrayList<T>)
}

Description: Implements the iterator function of ArrayList.

Parent Type:

init(ArrayList<T>)

public init(data: ArrayList<T>)

Description: Creates an ArrayListIterator<T> instance.

Parameters:

  • date: passed ArrayList<T>

func next()

public func next(): Option<T>

Description: Returns the next element in an iterator.

Returns:

  • ?T: next element in the iterator, which is encapsulated by Option

Throws:

func iterator()

public func iterator(): Iterator<T>

Description: Returns an iterator itself.

Returns:

class HashMapIterator<K, V> where K <: Hashable & Equatable<K>

public class HashMapIterator<K, V> <: Iterator<(K, V)> where K <: Hashable & Equatable<K> {
    public init(map: HashMap<K, V>)
}

Description: Implements the iterator function of HashMap.

Parent Type:

init(HashMap<K, V>)

public init(map: HashMap<K, V>)

Description: Creates a HashMapIterator<K, V> instance.

Parameters:

func iterator()

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

Description: Returns an iterator instance itself.

Returns:

  • Iterator <(K, V) >: iterator instance itself

func next()

public func next(): ?(K, V)

Description: Returns the next element in an iterator.

Returns:

  • ?(K, V): next element in the iterator, which is encapsulated by Option

Throws:

func remove()

public func remove(): Option<(K, V)>

Description: Deletes the elements returned by the next function of the iterator of HashMap. This function can be called only once when the next function is called.

Returns:

  • Option <(K, V) >: deleted elements

Throws:

class HashMap<K, V> where K <: Hashable & Equatable<K>

public class HashMap<K, V> <: Map<K, V> where K <: Hashable & Equatable<K> {
    public init()
    public init(elements: Collection<(K, V)>)
    public init(elements: Array<(K, V)>)
    public init(capacity: Int64)
    public init(size: Int64, initElement: (Int64) -> (K, V))
}

Description: Specifies the hash table implementation of the Map interface.

A hash table is a common data structure that can be used to quickly search for, insert, and delete data. The basic principle of a hash table is to map data to an array, which is called a hash table. Each data element has a corresponding hash value, and the hash value can be used to determine a location of the element in a hash table.

The features of hash tables are fast search, insertion, and deletion operations, and the time complexity is usually O(1). Since the array size at the bottom layer of a hash table is dynamic, the hash table cannot ensure that the order of elements is immutable.

Parent Type:

prop size

public prop size: Int64

Description: Returns the number of key-value pairs.

Type: Int64

init()

public init()

Description: Constructs a HashMap instance whose default initial capacity is 16 and default load factor is empty.

init(Array<(K, V)>)

public init(elements: Array<(K, V)>)

Description: Constructs a HashMap instance based on the passed key-value pair array.

This constructor sets the capacity of HashMap based on the size of the passed array. Duplicate keys are not allowed in HashMap. Therefore, when duplicate keys exist in Array, the key-value pair that appears later overwrites the key-value pair of the duplicate key based on the iterator order.

Parameters:

  • elements: Array<(K, V)>: key-value pair array used to initialize the HashMap instance

init(Collection<(K, V)>)

public init(elements: Collection<(K, V)>)

Description: Constructs a HashMap instance based on the passed key-value pair collection.

This constructor sets the capacity of HashMap based on the size of the passed collection elements. Duplicate keys are not allowed in HashMap. Therefore, when duplicate keys exist in Array, the key-value pair that appears later overwrites the key-value pair of the duplicate key based on the iterator order.

Parameters:

  • elements: Collection<(K, V)>: key-value pair collection used to initialize the HashMap instance

init(Int64)

public init(capacity: Int64)

Description: Constructs a HashMap instance with a passed capacity.

Parameters:

  • capacity: Int64: initial capacity

Throws:

init(Int64, (Int64) -> (K, V))

public init(size: Int64, initElement: (Int64) -> (K, V))

Description: Constructs a HashMap instance based on the passed element quantity size and function rule.

The capacity of the constructed HashMap instance is affected by size. Duplicate keys are not allowed in HashMap. Therefore, when the initElement function generates a duplicate key, the key-value pair constructed later overwrites the key-value pair of the duplicate key.

Parameters:

  • size: Int64: function rule used to initialize the HashMap instance
  • initElement: (Int64) ->(K, V): function rule used to initialize the HashMap instance

Throws:

func capacity()

public func capacity(): Int64

Description: Returns the capacity of a HashMap instance.

Returns:

func clear()

public func clear(): Unit

Description: Clears all key-value pairs.

Example:

For details, see [putAll, remove, and clear functions of HashMap] (../collection_package_samples/sample_hashmap_putall_remove_clear.md).

func clone()

public func clone(): HashMap<K, V>

Description: Clones a HashMap instance.

Returns:

func contains(K)

public 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 key is included, true is returned. Otherwise, false is returned.

Example:

For details, see [get, put, and contains functions of Hashmap] (../collection_package_samples/sample_hashmap_get_put_contains.md).

func containsAll(Collection<K>)

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

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

Parameters:

Returns:

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

func entryView(K)

public func entryView(key: K): EntryView<K, V>

Description: Returns an empty reference view if a specific key is not included. If the specific key is included, the reference view of the element corresponding to the key is returned.

For details about how to use EntryView, see EntryView.

Parameters:

  • key: K: key of the key-value pair to be added

Returns:

func get(K)

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

Description: Returns the value mapped to a specified key. If HashMap does not contain the mapping of the specified key, Option<V>.None is returned.

Parameters:

  • key: K: passed key

Returns:

  • Option<V>: value corresponding to the key, which is encapsulated by Option

Example:

For details, see [get, put, and contains functions of Hashmap] (../collection_package_samples/sample_hashmap_get_put_contains.md).

func isEmpty()

public func isEmpty(): Bool

Description: Checks whether a HashMap instance is empty. If yes, true is returned. If no, false is returned.

Returns:

  • Bool: result of whether the HashMap instance is empty

func iterator()

public func iterator(): HashMapIterator<K, V>

Description: Returns an iterator of Hashmap.

Returns:

func keys()

public func keys(): EquatableCollection<K>

Description: Returns all keys in a HashMap instance and stores them in a Keys container.

Returns:

func put(K, V)

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

Description: Puts a key-value pair into a HashMap instance.

For an existing key in the HashMap instance that is the same as the new key to be passed, the value of the existing key is replaced with the new value and the old existing value is returned.

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.

Example:

For details, see [get, put, and contains functions of Hashmap] (../collection_package_samples/sample_hashmap_get_put_contains.md).

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

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

Description: Puts a new key-value pair collection into a HashMap instance based on the iterator order of elements.

For an existing key in the HashMap instance that is the same as the new key to be passed, the value of the key is replaced with the new value.

Parameters:

  • elements: Collection<(K, V)>: key-value pair collection to be added to the HashMap instance

Example:

For details, see [putAll, remove, and clear functions of HashMap] (../collection_package_samples/sample_hashmap_putall_remove_clear.md).

func putIfAbsent(K, V)

public func putIfAbsent(key: K, value: V): Bool

Description: Inserts a key-value pair (key, value) into a HashMap instance if key does not exist in the HashMap instance.

Parameters:

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

Returns:

  • Bool: If key exists before value allocation, false is returned. Otherwise, true is returned.

func remove(K)

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

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

Parameters:

  • key: K: key to be deleted

Returns:

  • Option<V>: value corresponding to the key removed from the HashMap instance, which is encapsulated with Option. If key does not exist in the HashMap instance, None is returned.

Example:

For details, see [putAll, remove, and clear functions of HashMap] (../collection_package_samples/sample_hashmap_putall_remove_clear.md).

func removeAll(Collection<K>)

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

Description: Deletes the mappings (if any) of keys in a specified collection from a HashMap instance.

Parameters:

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

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

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

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

This function traverses the entire HashMap instance and deletes all key-value pairs that meet predicate(K, V) = = true.

Parameters:

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

Throws:

func reserve(Int64)

public func reserve(additional: Int64): Unit

Description: Expands the capacity of the current HashMap instance.

Expands the capacity of HashMap by additional. When additional is less than or equal to 0, capacity is not expanded. When the remaining capacity of HashMap is greater than or equal to additional, capacity is not expanded. When the remaining capacity of HashMap is less than additional, capacity is expanded to the larger value of (1.5 times the rounded-down original capacity) and (additional + used capacity).

Parameters:

  • additional: Int64: size to which capacity is expanded

Throws:

  • OverflowException: If the sum of additional capacity and used capacity exceeds Int64.Max, this exception is thrown.

func toArray()

public func toArray(): Array<(K, V)>

Description: Constructs an array containing key-value pairs in a HashMap instance and returns the array.

Returns:

  • Array <(K, V) >: array containing all key-value pairs in the container

func values()

public func values(): Collection<V>

Description: Returns all values contained in a HashMap instance and stores them in a Values container.

Returns:

operator func [](K, V)

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

Description: Overrides the put method. 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 used for judgment
  • value!: V: value to be set

operator func [](K)

public operator func [](key: K): V

Description: Overrides the get method. If key exists, the value corresponding to key is returned.

Parameters:

  • key: K: key used for judgment

Returns:

  • V: value corresponding to the key

Throws:

extend<K, V> HashMap<K, V> <: Equatable<HashMap<K, V>> where V <: Equatable<V>

extend<K, V> HashMap<K, V> <: Equatable<HashMap<K, V>> where V <: Equatable<V>

Description: Extends the Equatable<HashMap<K, V>> interface for the HashMap<K, V> type to support the equality check operation.

Parent Type:

operator func ==(HashMap<K, V>)

public operator func ==(right: HashMap<K, V>): Bool

Description: Checks whether the current instance is equal to the HashMap<K, V> instance specified by the right parameter.

Two HashMap<K, V> instances being equal means that key-value pairs included the two instances are completely equal.

Parameters:

  • right: HashMap<K, V>: objects to be compared

Returns:

  • Bool: If the two instances are equal, true is returned. Otherwise, false is returned.

operator func !=(HashMap<K, V>)

public operator func !=(right: HashMap<K, V>): Bool

Description: Checks whether the current instance is not equal to the HashMap<K, V> instance specified by the right parameter.

Parameters:

  • right: HashMap<K, V>: objects to be compared

Returns:

  • Bool: If the two instances are not equal, true is returned. Otherwise, false is returned.

extend<K, V> HashMap<K, V> <: ToString where V <: ToString, K <: ToString

extend<K, V> HashMap<K, V> <: ToString where V <: ToString, K <: ToString

Description: Extends the ToString interface for HashMap<K, V> to support string conversion.

Parent Type:

func toString()

public func toString(): String

Description: Converts the current HashMap<K, V> instance to a string.

The string contains the string representation of each key-value pair in the HashMap<K, V> instance, for example, "[(k1, v1), (k2, v2), (k3, v3)]".

Returns:

  • String: string after conversion

class HashSet<T> where T <: Hashable & Equatable<T>

public class HashSet<T> <: Set<T> where T <: Hashable & Equatable<T> {
    public init()
    public init(elements: Collection<T>)
    public init(elements: Array<T>)
    public init(capacity: Int64)
    public init(size: Int64, initElement: (Int64) -> T)
}

Description: Specifies the instance of the Set interface implemented based on HashMap.

The elements in HashSet are unordered and cannot contain duplicate elements. When an element is added to HashSet, HashSet determines the location of the element in the hash table based on the hash value of the element.

Note:

HashSet is implemented based on HashMap. Therefore, the capacity, memory layout, and time performance of HashSet are the same as those of HashMap.

Parent Type:

prop size

public prop size: Int64

Description: Returns the number of elements of a HashSet instance.

Type: Int64

init(Int64, Int64 -> T)

public init(size: Int64, initElement: (Int64) -> T)

Description: Constructs a HashSet instance based on the passed function element quantity size and function rule. The capacity of the constructed HashSet instance is affected by size.

Parameters:

  • size: Int64: initial element quantity
  • initElement: (Int64) ->T: initialization function rule

Throws:

init()

public init()

Description: Constructs an empty HashSet instance with an initial capacity of 16.

init(Array<T>)

public init(elements: Array<T>)

Description: Constructs a HashSet instance using a passed array. This constructor sets the capacity of HashSet based on size of the passed elements array.

Parameters:

  • elements: Array<T>: array used to initialize the HashSet instance

init(Collection<T>)

public init(elements: Collection<T>)

Description: Constructs a HashSet instance using a passed collection. This constructor sets the capacity of HashSet based on size of the passed elements collection.

Parameters:

init(Int64)

public init(capacity: Int64)

Description: Constructs a HashSet instance using a passed capacity.

Parameters:

  • capacity: Int64: initial capacity

Throws:

func capacity()

public func capacity(): Int64

Description: Returns the internal array capacity of a HashSet instance.

Note:

The capacity may not be equal to the size of the HashSet instance.

Returns:

func clear()

public func clear(): Unit

Description: Removes all elements from a HashSet instance.

func clone()

public func clone(): HashSet<T>

Description: Clones a HashSet instance.

Returns:

func contains(T)

public func contains(element: T): Bool

Description: Checks whether a HashSet instance contains a specified element.

Parameters:

  • element: T: specified element

Returns:

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

func containsAll(Collection<T>)

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

Description: Checks whether a HashSet instance contains all elements in the specified Collection instance.

Parameters:

  • elements: Collection<T>: specified element collection

Returns:

  • Bool: If the HashSet instance contains all elements in the specified Collection instance, true is returned. Otherwise, false is returned.

func isEmpty()

public func isEmpty(): Bool

Description: Checks whether a HashSet instance is empty.

Returns:

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

func iterator()

public func iterator(): Iterator<T>

Description: Returns the iterator of a HashSet instance.

Returns:

Example:

For details, see [put, iterator, and remove functions of HashSet] (../collection_package_samples/sample_hashset_put_iterator_remove.md).

func put(T)

public func put(element: T): Bool

Description: Adds a specified element to a HashSet instance. If the element to be added exists in the HashSet instance, the element fails to be added.

Parameters:

  • element: T: specified element

Returns:

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

Example:

For details, see [put, iterator, and remove functions of HashSet] (../collection_package_samples/sample_hashset_put_iterator_remove.md).

func putAll(Collection<T>)

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

Description: Adds all elements in a Collection instance to a HashSet 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)

public func remove(element: T): Bool

Description: Removes a specified element if it exists in a HashSet instance.

Parameters:

  • element: T: element to be removed

Returns:

  • Bool: true indicating that the removal is successful; false indicating that the removal fails

Example:

For details, see [put, iterator, and remove functions of HashSet] (../collection_package_samples/sample_hashset_put_iterator_remove.md).

func removeAll(Collection<T>)

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

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

Parameters:

  • elements: Collection<T>: collection of elements to be removed from the HashSet instance

func removeIf((T) -> Bool)

public 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: condition for determining whether to delete an element

Throws:

  • ConcurrentModificationException: If addition, deletion, or modification of key-value pairs is performed on [HashSet](collection_package_class.md#class-hashsett-where-t--hashable--equatablet) through predicate, this exception is thrown.

func reserve(Int64)

public func reserve(additional: Int64): Unit

Description: Expands the capacity of HashSet by additional. When additional is less than or equal to 0, capacity is not expanded. When the remaining capacity of HashSet is greater than or equal to additional, capacity is not expanded. When the remaining capacity of HashSet is less than additional, capacity is expanded to the larger value of (1.5 times the rounded-down original capacity) and (additional + used capacity).

Parameters:

  • additional: Int64: size to which capacity is expanded

Throws:

  • OverflowException: If the sum of additional capacity and used capacity exceeds Int64.Max, this exception is thrown.

func retainAll(Set<T>)

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

Description: Retains the elements in a Set instance from a HashSet instance.

Parameters:

  • elements: Set<T>: Set instance to be retained

func subsetOf(Set<T>)

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

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

Parameters:

  • other: Set<T>: set to be passed. This function checks whether the current set is a subset of other.

Returns:

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

func toArray()

public func toArray(): Array<T>

Description: Returns an array containing all elements in a container.

Returns:

extend<T> HashSet<T> <: Equatable<HashSet<T>>

extend<T> HashSet<T> <: Equatable<HashSet<T>>

Description: Extends the Equatable<HashSet<T>> interface for the HashSet<T> type to support the equality check operation.

Parent Type:

operator func ==(HashSet<T>)

public operator func ==(that: HashSet<T>): Bool

Description: Checks whether the current instance is equal to the HashSet<T> instance specified by the that parameter.

Two HashSet<T> instances being equal means that elements included in the two instances are completely equal.

Parameters:

  • that: HashSet<T>: instance to be compared with

Returns:

  • Bool: If the two instances are equal, true is returned. Otherwise, false is returned.

operator func !=(HashSet<T>)

public operator func !=(that: HashSet<T>): Bool

Description: Checks whether the current instance is not equal to the HashSet<T> instance specified by the that parameter.

Parameters:

  • that: HashSet<T>: instance to be compared with

Returns:

  • Bool: If the two instances are not equal, true is returned. Otherwise, false is returned.

extend<T> HashSet<T> <: ToString where T <: ToString

extend<T> HashSet<T> <: ToString where T <: ToString

Description: Extends the ToString interface for HashSet<T> to support string conversion.

Parent Type:

func toString()

public func toString(): String

Description: Converts the current HashSet<T> instance to a string.

The string contains the string representation of each element in a HashSet<T> instance, for example, "[elem1, elem2, elem3]".

Returns:

  • String: string after conversion

class LinkedListNode<T>

public class LinkedListNode<T>

Description: a LinkedListNode instance is a node on a LinkedList instance.

LinkedListNode can be used to traverse forward and backward LinkedList to access and modify element values.

LinkedListNode can be obtained only through 'nodeAt', 'firstNode', and 'lastNode' of the corresponding LinkedList instance. When the corresponding node is deleted from the LinkedList instance, a dangling node is generated. Any operation on the dangling node triggers an 'IllegalStateException' exception.

prop next

public prop next: Option<LinkedListNode<T>>

Description: Obtains the next node of the current node. If there is no next node, None is returned.

Type: Option<LinkedListNode<T>>

Throws:

  • IllegalStateException: If the node does not belong to any linked list instance, this exception is thrown.

prop prev

public prop prev: Option<LinkedListNode<T>>

Description: Obtains the previous node of the current node. If there is no previous node, None is returned.

Type: Option<LinkedListNode<T>>

Throws:

  • IllegalStateException: If the node does not belong to any linked list instance, this exception is thrown.

prop value

public mut prop value: T

Description: Obtains or modifies the value of an element.

Type: T

Throws:

  • IllegalStateException: If the node does not belong to any linked list instance, this exception is thrown.

func backward()

public func backward(): Iterator<T>

Description: Obtains an iterator of all elements from the current node to the last node of the corresponding linked list.

Returns:

  • Iterator<T>: iterator of the corresponding elements

Throws:

  • IllegalStateException: If the node does not belong to any linked list instance, this exception is thrown.

func forward()

public func forward(): Iterator<T>

Description: Obtains an iterator of all elements from the current node to the first node of the corresponding linked list.

Returns:

  • Iterator<T>: iterator of the corresponding elements

Throws:

  • IllegalStateException: If the node does not belong to any linked list instance, this exception is thrown.

class LinkedList<T>

public class LinkedList<T> <: Collection<T> {
    public init()
    public init(elements: Collection<T>)
    public init(elements: Array<T>)
    public init(size: Int64, initElement: (Int64)-> T)
}

Description: Specifies the data structure with doubly linked list mode implemented.

A doubly linked list is a common data structure. It consists of a series of nodes. Each node contains two pointers, one pointing to the previous node and the other pointing to the next node. This structure allows bidirectional traversal on any node. The traversal can start from the first node or may start from the last node.

LinkedList does not support concurrent operations. Modifying elements in LinkedList does not invalidate the iterator. The iterator becomes invalid only when elements are added or deleted.

Parent Type:

prop first

public prop first: ?T

Description: Returns the value of the first element in a linked list. If the linked list is empty, None is returned.

Type: ?T

prop last

public prop last: ?T

Description: Returns the value of the last element in a linked list. If the linked list is empty, None is returned.

Type: ?T

prop size

public prop size: Int64

Description: Obtains the number of elements in a linked list.

Type: Int64

init

public init()

Description: Constructs an empty linked list.

init(Array<T>)

public init(elements: Array<T>)

Description: Constructs a LinkedList instance that contains elements of a specified collection based on the traversal order of an array.

Parameters:

  • elements: Array<T>: element array to be put into the linked list

init(Collection<T>)

public init(elements: Collection<T>)

Description: Constructs a linked list that contains elements of a specified collection based on the order of elements returned from the iterator of a collection.

Parameters:

  • elements: Collection<T>: element collection to be put into the linked list

init(Int64, (Int64)-> T)

public init(size: Int64, initElement: (Int64)-> T)

Description: Creates a linked list that contains size elements and in which the nth element meets the (Int64)-> T condition.

Parameters:

  • size: Int64: number of linked list elements to be created
  • initElement: (Int64) ->T: initialization parameter of elements

func append(T)

public func append(element: T): LinkedListNode<T>

Description: Adds an element to the end of a linked list and returns the node of the element.

Parameters:

  • element: T: element to be added to the linked list

Returns:

func clear()

public func clear(): Unit

Description: Deletes all elements in a linked list.

func firstNode()

public func firstNode(): Option<LinkedListNode<T>>

Description: Obtains the node of the first element in a linked list.

Returns:

  • Option < LinkedListNode<T>>: node of the first element. If the linked list is empty, None is returned.

func insertAfter(LinkedListNode<T>,T)

public func insertAfter(node: LinkedListNode<T>, element: T): LinkedListNode<T>

Description: Inserts an element after a specified node in a linked list and returns the node of the element.

Parameters:

  • node: LinkedListNode<T>: specified node
  • element: T: element to be added to the linked list

Returns:

Throws:

  • IllegalArgumentException: If the specified node does not belong to the original linked list, this exception is thrown.

func insertBefore(LinkedListNode<T>,T)

public func insertBefore(node: LinkedListNode<T>, element: T): LinkedListNode<T>

Description: Inserts an element before a specified node in a linked list and returns the node of the element.

Parameters:

  • node: LinkedListNode<T>: specified node
  • element: T: element to be added to the linked list

Returns:

Throws:

  • IllegalArgumentException: If the specified node does not belong to the original linked list, this exception is thrown.

func isEmpty()

public func isEmpty(): Bool

Description: Checks whether a linked list is empty.

Returns:

  • Bool: true is returned if the linked list does not contain any element.

func iterator()

public func iterator(): Iterator<T>

Description: Returns the iterator of elements in the current collection. Its order is from the first node of the linked list to the last node of the linked list.

Returns:

  • Iterator<T>: iterator of elements in the current collection

func lastNode()

public func lastNode(): Option<LinkedListNode<T>>

Description: Obtains the node of the last element in a linked list.

Returns:

  • Option < LinkedListNode<T>>: node of the last element. If the linked list is empty, None is returned.

func nodeAt(Int64)

public func nodeAt(index: Int64): Option<LinkedListNode<T>>

Description: Obtains the node of the element with the number of index in a linked list. The number starts from 0.

Time complexity of this function is O(n).

Parameters:

  • index: Int64: index specifying the node of the element to be obtained

Returns:

  • Option < LinkedListNode<T>>: node with the number of index. If there is no node with the number of index, None is returned.

func popFirst()

public func popFirst() : ?T

Description: Removes the first element of a linked list and returns the value of this element.

Returns:

  • ?T: value of the deleted element. If the linked list is empty, None is returned.

func popLast()

public func popLast() : ?T

Description: Removes the last element of a linked list and returns the value of this element.

Returns:

  • ?T: value of the deleted element. If the linked list is empty, None is returned.

func prepend(T)

public func prepend(element: T): LinkedListNode<T>

Description: Inserts an element into the head of a linked list and returns the node of the element.

Parameters:

  • element: T: element to be added to the linked list

Returns:

func remove(LinkedListNode<T>)

public func remove(node: LinkedListNode<T>): T

Description: Deletes a specified node in a linked list.

Parameters:

Returns:

  • T: value of the deleted node

Throws:

  • IllegalArgumentException: If the specified node does not belong to the original linked list, this exception is thrown.

func removeIf((T)-> Bool)

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

Description: Deletes all elements that meet the specified lambda expression or function in a linked list.

Parameters:

  • predicate: (T) ->Bool: true for the element to be deleted

func reverse()

public func reverse(): Unit

Description: Reverses the order of elements in a linked list.

func splitOff(LinkedListNode<T>)

public func splitOff(node: LinkedListNode<T>): LinkedList<T>

Description: Splits a linked list into two linked lists starting from a node specified by node. If the splitting is successful, node is not in the current linked list but exists in the new linked list as the first node.

Parameters:

Returns:

  • LinkedList<T>: linked list generated after the original linked list is split

Throws:

  • IllegalArgumentException: If the specified node does not belong to the original linked list, this exception is thrown.

func toArray()

public func toArray(): Array<T>

Description: Returns an array that contains all elements in a linked list in the same order as the linked list.

Returns:

extend<T> LinkedList<T> <: Equatable<LinkedList<T>> where T <: Equatable<T>

extend<T> LinkedList<T> <: Equatable<LinkedList<T>> where T <: Equatable<T>

Description: Extends the Equatable<LinkedList<T>> interface for the LinkedList<T> type to support the equality check operation.

Parent Type:

operator func ==(LinkedList<T>)

public operator func ==(right: LinkedList<T>): Bool

Description: Checks whether the current instance is equal to the LinkedList<T> instance specified by the right parameter.

Two LinkedList<T> instances being equal means that elements included in the two instances are completely equal.

Parameters:

  • right: HashSet<T>: objects to be compared

Returns:

  • Bool: If the two instances are equal, true is returned. Otherwise, false is returned.

operator func !=(LinkedList<T>)

public operator func !=(right: LinkedList<T>): Bool

Description: Checks whether the current instance is not equal to the LinkedList<T> instance specified by the right parameter.

Parameters:

Returns:

  • Bool: If the two instances are not equal, true is returned. Otherwise, false is returned.

extend<T> LinkedList<T> <: ToString where T <: ToString

extend<T> LinkedList<T> <: ToString where T <: ToString

Description: Extends the ToString interface for LinkedList<T> to support string conversion.

Parent Type:

func toString()

public func toString(): String

Description: Converts the current LinkedList<T> instance to a string.

The string contains the string representation of each element in a LinkedList<T> instance, for example, "[elem1, elem2, elem3]".

Returns:

  • String: string after conversion

class TreeMap<K, V> where K <: Comparable<K>

public class TreeMap<K, V> <: Map<K, V> where K <: Comparable<K> {
    public init()
    public init(elements: Collection<(K, V)>)
    public init(elements: Array<(K,V)>)
    public init(size: Int64, initElement: (Int64) -> (K, V))
}

Description: Specifies the class of Map interface implemented based on the balanced binary search tree.

This class provides an ordered key-value storage structure, which supports quickly inserting, deleting, and searching for elements.

TreeMap can be used in any scenario where ordered key-value pair storage is required, such as databases, caches, and lookup tables.

Parent Type:

prop size

public prop size: Int64

Description: Returns the number of key-value pairs.

Type: Int64

init()

public init()

Description: Constructs an empty TreeMap instance.

init(Array<(K,V)>)

public init(elements: Array<(K,V)>)

Description: Constructs a TreeMap instance based on the passed key-value pair array.

Inserts elements into a TreeMap instance in the order of elements. Duplicate keys are not allowed in the TreeMap instance. If elements contain duplicate keys, the key-value pair that appears earlier is overwritten.

Parameters:

  • elements: Array<(K, V)>: key-value pair array used to initialize the TreeMap instance

init(Collection<(K, V)>)

public init(elements: Collection<(K, V)>)

Description: Constructs a TreeMap instance based on the passed key-value pair collection.

Inserts elements into a TreeMap instance in the iterator order of elements. Duplicate keys are not allowed in the TreeMap instance. If elements contain duplicate keys, the key-value pair that appears earlier (determined based on the iterator order) is overwritten

Parameters:

  • elements: Collection<(K, V)>: key-value pair collection used to initialize the TreeMap instance

init(Int64, (Int64) -> (K, V))

public init(size: Int64, initElement: (Int64) -> (K, V))

Description: Constructs a TreeMap instance based on the passed element quantity size and function rule.

Parameters:

  • size: Int64: passed element quantity
  • initElement: (Int64) ->(K, V): function rule used to initialize the TreeMap instance

Throws:

func clear()

public func clear(): Unit

Description: Clears all key-value pairs.

func clone()

public func clone(): TreeMap<K, V>

Description: Clones a TreeMap instance.

Returns:

func contains(K)

public 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 key is included, true is returned. Otherwise, false is returned.

func containsAll(Collection<K>)

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

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

Parameters:

Returns:

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

func findLower(K, Bool)

public func findLower(bound: K, inclusive!: Bool = false): Option<TreeMapNode<K, V>>

Description: Returns the maximum element that is smaller than the value of the passed key.

Parameters:

  • bound: K: passed key
  • inclusive!: Bool: whether to contain the passed key itself; default value: false (no)

Returns:

func findUpper(K, Bool)

public func findUpper(bound: K, inclusive!: Bool = false): Option<TreeMapNode<K, V>>

Description: Returns the minimum element that is greater than the value of the passed key.

Parameters:

  • bound: K: passed key
  • inclusive!: Bool: whether to contain the passed key itself; default value: false (no)

Returns:

func firstEntry()

public func firstEntry(): Option<(K, V)>

Description: Obtains the first element of a TreeMap instance.

Returns:

  • Option <(K, V): The element (if there is) is returned after encapsulated with Option. Otherwise, Option<(K, V)>.None is returned.

func get(K)

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

Description: Returns the value of a specified key mapping.

Parameters:

  • key: K: specified key

Returns:

  • Option<V>: The value (if there is) is returned after encapsulated with Option. Otherwise, Option<V>.None is returned.

func isEmpty()

public func isEmpty(): Bool

Description: Check whether a TreeMap instance is empty.

Returns:

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

func iterator()

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

Description: Returns the iterator of a TreeMap instance. The iterator iterates in ascending order of Key values.

Returns:

func keys()

public func keys(): EquatableCollection<K>

Description: Returns all keys in a TreeMap instance and stores them in a container.

Returns:

func lastEntry()

public func lastEntry(): Option<(K, V)>

Description: Obtains the last element of a TreeMap instance.

Returns:

  • Option <(K, V): The element (if there is) is returned after encapsulated with Option. Otherwise, Option<(K, V)>.None is returned.

func popFirstEntry()

public func popFirstEntry(): Option<(K, V)>

Description: Deletes the first element of a TreeMap instance.

Returns:

  • Option <(K, V): The element (if there is) is deleted and returned after encapsulated with Option. Otherwise, Option<(K, V)>.None is returned.

func popLastEntry()

public func popLastEntry(): Option<(K, V)>

Description: Deletes the last element of a TreeMap instance.

Returns:

  • Option <(K, V): The element (if there is) is deleted and returned after encapsulated with Option. Otherwise, Option<(K, V)>.None is returned.

func put(K, V)

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

Description: Puts a new key-value pair into a TreeMap instance. For an existing key in the TreeMap instance that is the same as the new key to be passed, the value of 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 returned after encapsulated with Option. Otherwise, Option<V>.None is returned.

func putAll(Collection<K, V>)

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

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

Parameters:

  • elements: Collection<(K, V)>: key-value pair collection to be added to the TreeMap instance

func remove(K)

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

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

Parameters:

  • key: K: key to be deleted

Returns:

  • Option<V>: The value of the removed mapping is encapsulated with Option. If the specified key does not exist in TreeMap, None is returned.

func removeAll(Collection<K>)

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

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

Parameters:

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

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

public 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()

public func values(): Collection<V>

Description: Returns all values in a TreeMap instance and stores them in a container.

Returns:

operator func [](K, V)

public 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 used for judgment
  • value!: V: value to be set

operator func [](K)

public operator func [](key: K): V

Description: Overrides the indexing operator. If key exists, the value corresponding to key is returned.

Parameters:

  • key: K: key used for judgment

Returns:

  • V: value corresponding to the key

Throws:

extend<K, V> TreeMap<K, V> <: Equatable<TreeMap<K, V>> where V <: Equatable<V>

extend<K, V> TreeMap<K, V> <: Equatable<TreeMap<K, V>> where V <: Equatable<V>

Description: Extends the Equatable<TreeMap<K, V>> interface for the TreeMap<K, V> type to support the equality check operation.

Parent Type:

operator func ==(TreeMap<K, V>)

public operator func ==(right: TreeMap<K, V>): Bool

Description: Checks whether the current instance is equal to the TreeMap<K, V> instance specified by the right parameter.

Two TreeMap<K, V> instances being equal means that key-value pairs included the two instances are completely equal.

Parameters:

  • right: TreeMap<K, V>: objects to be compared

Returns:

  • Bool: If the two instances are equal, true is returned. Otherwise, false is returned.

operator func !=(TreeMap<K, V>)

public operator func !=(right: TreeMap<K, V>): Bool

Description: Checks whether the current instance is not equal to the TreeMap<K, V> instance specified by the right parameter.

Parameters:

  • right: TreeMap<K, V>: objects to be compared

Returns:

  • Bool: If the two instances are not equal, true is returned. Otherwise, false is returned.

extend<K, V> TreeMap<K, V> <: ToString where V <: ToString, K <: ToString & Comparable<K>

extend<K, V> TreeMap<K, V> <: ToString where V <: ToString, K <: ToString & Comparable<K>

Description: Extends the ToString interface for TreeMap<K, V> to support string conversion.

Parent Type:

func toString()

public func toString(): String

Description: Converts the current TreeMap<K, V> instance to a string.

The string contains the string representation of each key-value pair in the TreeMap<K, V> instance, for example, "[(k1, v1), (k2, v2), (k3, v3)]".

Returns:

  • String: string after conversion