Classes

class ArrayDeque<T>

public class ArrayDeque<T> <: Deque<T> {
    public init()
    public init(capacity: Int64)
}

Description: Inserts or deletes elements at both ends of a double-ended queue as a double-ended queue (Deque) implementation class. ArrayDeque is implemented based on resizable arrays. The capacity of ArrayDeque increases continuously during element insertion. By default, the capacity is expanded by 50% each time. ArrayDeque is implemented in cyclic queue mode. If no capacity expansion is performed, the time complexity of operations such as insertion, deletion, and query is O(1).

Parent types:

prop capacity

public prop capacity: Int64

Description: Obtains the capacity of a double-ended queue.

Type: Int64

prop first

public prop first: ?T

Description: Obtains the head element of a double-ended queue. If the double-ended queue is empty, None is returned.

Type: Option<T>

prop last

public prop last: ?T

Description: Obtains the last element of a double-ended queue. If the double-ended queue is empty, None is returned.

Type: Option<T>

prop size

public prop size: Int64

Description: Obtains the number of elements in a double-ended queue.

Type: Int64

init()

public init()

Description: Constructs an empty double-ended queue with the default capacity of 8.

init(Int64)

public init(capacity: Int64)

Description: Constructs a double-ended queue with a specified capacity. When the capacity is less than the default capacity 8, the initial capacity of the constructed ArrayDeque is 8.

Parameters:

  • capacity: Int64: initial capacity

Throws:

func addFirst(T)

public func addFirst(element: T): Unit

Description: Inserts an element to the head of a double-ended queue.

Parameters:

  • element: T: element inserted into the double-ended queue

func addLast(T)

public func addLast(element: T): Unit

Description: Inserts a last element to the end of a double-ended queue.

Parameters:

  • element: T: element inserted into the double-ended queue

func clear()

public func clear(): Unit

Description: Deletes all elements from a double-ended queue.

func iterator()

public func iterator(): Iterator<T>

Description: Obtains the iterator of elements in a double-ended queue in sequence.

Returns:

func isEmpty()

public func isEmpty(): Bool

Description: Checks whether a double-ended queue is empty.

Returns:

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

func removeFirst()

public func removeFirst(): ?T

Description: Deletes the head element from a double-ended queue and returns a value. If the double-ended queue is empty, None is returned.

Returns:

  • ?T: head element that is deleted

func removeLast()

public func removeLast(): ?T

Description: Deletes the last element from a double-ended queue and returns a value. If the double-ended queue is empty, None is returned.

Returns:

  • ?T: last element that is deleted

func reserve(Int64)

public func reserve(additional: Int64): Unit

Description: Expands the capacity of a double-ended queue.

This function expands the double-ended queue by the value of additional. When the value of additional is less than or equal to 0, capacity expansion is not performed. When the remaining capacity of the double-ended queue is greater than or equal to the value of additional, capacity expansion is not performed. When the remaining capacity of the double-ended queue is less than the value of additional, the larger one in the value obtained after 1.5 times of the original capacity is rounded down and the value of additional plus the used capacity is used for capacity expansion.

Parameters:

  • additional: Int64: size for capacity expansion

func toArray()

public func toArray(): Array<T>

Description: Returns an array containing all elements in a double-ended queue in sequence.

Returns:

  • Array<T>: array of the T type

extend<T> ArrayDeque<T> <: ToString where T <: ToString

extend<T> ArrayDeque<T> <: ToString where T <: ToString

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

Parent types:

func toString()

public func toString(): String

Description: Obtains the string representation of an ArrayDeque<T> instance.

The string contains the string representation of each element in the double-ended queue in sequence, for example, [elem1, elem2, elem3].

Returns:

  • String: string after conversion

class ArrayList<T>

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

Description: Provides the functionalities of a variable-length array.

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.

  • For dynamic arrays, the memory usage can be reduced and the size can be automatically resized as required. Therefore, dynamic arrays are suitable for scenarios where elements need to be frequently added or deleted. However, the dynamic array performance may deteriorate when memory space is reallocated. Therefore, performance needs to be considered when dynamic arrays are used.

Parent types:

prop size

public prop size: Int64

Description: Obtains the number of elements in an ArrayList.

Type: Int64

prop capacity

public prop capacity: Int64

Description: Obtains the capacity of an ArrayList.

Type: Int64

prop first

public prop first: ?T

Description: Obtains the first element in an ArrayList. If there is no first element, None is returned.

Type: Option<T>

prop last

public prop last: ?T

Description: Obtains the last element in an ArrayList. If there is no last element, None is returned.

Type: Option<T>

init()

public init()

Description: Constructs an ArrayList instance with the default initial capacity of 16.

init(Collection<T>)

public init(elements: Collection<T>)

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

Parameters:

init(Int64)

public init(capacity: Int64)

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

Parameters:

  • capacity: Int64: initial capacity

Throws:

init(Int64, (Int64) -> T)

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

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

Parameters:

  • size: Int64: number of initialization function elements
  • initElement: (Int64) ->T: passed initialization function

Throws:

static func of(Array<T>)

public static func of(elements: Array<T>): ArrayList<T>

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

Parameters:

  • elements: Array<T>: passed array

Returns:

  • ArrayList<T>: ArrayList where the elements are of the T type

func add(T)

public func add(element: T): Unit

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

Parameters:

  • element: T: element of the T type to be inserted

Examples:

For details, see Add Function of ArrayList.

func add(Collection<T>)

public func add(all!: Collection<T>): Unit

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

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

Parameters:

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

func add(T, Int64)

public func add(element: T, at!: Int64): Unit

Description: Inserts a specified element to a specified position in an ArrayList.

Parameters:

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

Throws:

Examples:

For details, see Add Function of ArrayList.

func add(Collection<T>, Int64)

public func add(all!: Collection<T>, at!: Int64): Unit

Description: Inserts all elements of a specified collection to an ArrayList from a specified position.

The function traverses the collection specified by the input parameter in the element order of the iterator and inserts all elements to the specified position. The original elements at and after the specified position are moved backward.

Parameters:

  • all!: Collection<T>: collection of elements of the T type to be inserted
  • at!: Int64: target index of the collection to be inserted

Throws:

Examples:

For details, see Add Function of ArrayList.

func clear()

public func clear(): Unit

Description: Deletes all elements from an ArrayList.

Examples:

For details, see Remove, Clear, and Slice Functions of ArrayList.

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 an element at a specified position in an ArrayList.

Parameters:

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

Returns:

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

Examples:

For details, see Get and Set Functions of ArrayList.

func getRawArray()

public unsafe func getRawArray(): Array<T>

Description: Returns the raw data of an ArrayList.

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 the ArrayList. Its size is greater than or equal to the number of elements in the 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 isEmpty()

public func isEmpty(): Bool

Description: Checks whether an ArrayList is empty.

Returns:

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

func iterator()

public func iterator(): Iterator<T>

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

Returns:

func remove(Int64)

public func remove(at!: Int64): T

Description: Deletes an element at a specified position in an ArrayList.

Parameters:

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

Returns:

  • T: deleted element

Throws:

Examples:

For details, see Remove, Clear, and Slice Functions of ArrayList.

func remove(Range<Int64>)

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

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

NOTE

If the parameter range is a range instance constructed by using the range constructor and the value of 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 comply with a specified lambda expression or function from an ArrayList.

Parameters:

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

Throws:

func reserve(Int64)

public func reserve(additional: Int64): Unit

Description: Expands the capacity of an ArrayList instance.

This function expands the capacity of the ArrayList by the value of additional. When the value of additional is less than or equal to 0, capacity expansion is not performed. When the remaining capacity of the ArrayList is greater than or equal to the value of additional, capacity expansion is not performed. When the remaining capacity of the ArrayList is less than the value of additional, the larger one in the value obtained after 1.5 times of the original capacity is rounded down and the value of additional plus the used capacity is used for capacity expansion.

Parameters:

  • additional: Int64: size for capacity expansion

Throws:

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

func reverse()

public func reverse(): Unit

Description: Reverses the order of elements in an ArrayList.

func slice(Range<Int64>)

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

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

NOTE

If the parameter range is a range instance constructed by using the range constructor:

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

Parameters:

Returns:

Throws:

Examples:

For details, see Remove, Clear, and Slice Functions of ArrayList.

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

public func sortBy(comparator!: (T, T) -> Ordering): Unit

Description: Performs unstable sorting on 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 follows t2 after sorting. If the return value of comparator is Ordering.LT, t1 precedes t2 after sorting. If the return value of comparator is Ordering.EQ and stable sorting is conducted, t1 precedes t2. If the return value of comparator is Ordering.EQ and unstable sorting is conducted, the order of t1 and t2 is uncertain.

NOTE

This function will be deprecated in future releases and sort will be used instead.

Parameters:

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

public func sortBy(stable!: Bool, 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 follows t2 after sorting. If the return value of comparator is Ordering.LT, t1 precedes t2 after sorting. If the return value of comparator is Ordering.EQ and stable sorting is conducted, t1 precedes t2. If the return value of comparator is Ordering.EQ and unstable sorting is conducted, the order of t1 and t2 is uncertain.

NOTE

This function will be deprecated in future releases and sort will be used instead.

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:

  • Array<T>: array of the T type

operator func [](Int64)

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

Description: Overloads the get method.

Parameters:

  • index: Int64: index of the get API

Returns:

  • T: value of the element at the index location

Throws:

operator func [](Int64, T)

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

Description: Overloads the operator, that is, replaces an element at a specified position in a list with a specified element using an index operator.

Parameters:

  • index: Int64: index to be set
  • value!: T: value of the T type to be set

Throws:

operator func [](Range<Int64>)

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

Description: Overloads the slice operator.

NOTE

  • If the parameter range is a range instance constructed by using the range constructor:

    • The value of start is the value passed by the constructor and is not affected by the value of hasStart passed during construction.
    • When the value of hasEnd is false, the value of end does not take effect and is not affected by the value of isClosed passed 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 types:

operator func ==(ArrayList<T>)

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

Description: Checks whether an instance is the same as an ArrayList instance specified by the parameter.

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

Parameters:

  • that: ArrayList<T>: object 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 an instance is different from an ArrayList instance specified by the parameter.

Parameters:

  • that: ArrayList<T>: object 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 an array contains the element specified by 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> (deprecated)

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

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

NOTE

This function will be deprecated in future releases.

Parent types:

func sort() (deprecated)

public func sort(): Unit

Description: Performs unstable sorting on elements in an array in ascending order.

NOTE

This function will be deprecated in future releases and sort will be used instead.

func sort(Bool) (deprecated)

public func sort(stable!: Bool): Unit

Description: Sorts elements in an array in ascending order.

Parameters:

  • stable!: Bool: whether to use stable sorting

NOTE

This function will be deprecated in future releases and sort will be used instead.

func sortDescending() (deprecated)

public func sortDescending(): Unit

Description: Performs unstable sorting on elements in an array in descending order.

NOTE

This function will be deprecated in future releases and sort will be used instead.

func sortDescending(Bool) (deprecated)

public func sortDescending(stable!: Bool): Unit

Description: Sorts elements in an array in descending order.

Parameters:

  • stable!: Bool: whether to use stable sorting

NOTE

This function will be deprecated in future releases and sort will be used instead.

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

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

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

Parent types:

func toString()

public func toString(): String

Description: Converts an array into 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 ArrayQueue<T>

public class ArrayQueue<T> <: Queue<T> {
    public init()
    public init(capacity: Int64)
}

Description: Specifies the circular queue data structure implemented based on an array.

Parent types:

prop capacity

public prop capacity: Int64

Description: Obtains the capacity of a queue.

Type: Int64

prop size

public prop size: Int64

Description: Obtains the number of elements in a queue.

Type: Int64

init()

public init()

Description: Constructs an empty queue with the default capacity of 8.

init(Int64)

public init(capacity: Int64)

Description: Constructs a queue with a specified capacity. When the capacity is less than the default capacity 8, the initial capacity of the constructed ArrayQueue is 8.

Parameters:

  • capacity: Int64: initial capacity

Throws:

func add(T)

public func add(element: T): Unit

Description: Inserts an element to the end of a queue.

Parameters:

  • element: T: element inserted into the double-ended queue

func clear()

public func clear(): Unit

Description: Deletes all elements from a queue.

func iterator()

public func iterator(): Iterator<T>

Description: Obtains the iterator of elements in a queue in sequence.

Returns:

func isEmpty()

public func isEmpty(): Bool

Description: Checks whether a queue is empty.

Returns:

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

func peek()

public func peek():?T

Description: Checks the head element of a queue. This operation does not delete any element.

Returns:

  • ?T: head element of the queue. If the queue is empty, None is returned.

func remove()

public func remove(): ?T

Description: Deletes the head element from a queue and returns a value. If the queue is empty, None is returned.

Returns:

  • ?T: head element that is deleted

func reserve(Int64)

public func reserve(additional: Int64): Unit

Description: Expands the capacity of a queue.

This function expands the queue by the value of additional. When the value of additional is less than or equal to 0, capacity expansion is not performed. When the remaining capacity of the queue is greater than or equal to the value of additional, capacity expansion is not performed. When the remaining capacity of the queue is less than the value of additional, the larger one in the value obtained after 1.5 times of the original capacity is rounded down and the value of additional plus the used capacity is used for capacity expansion.

Parameters:

  • additional: Int64: size for capacity expansion

func toArray()

public func toArray(): Array<T>

Description: Returns an array containing all elements in a queue in sequence.

Returns:

  • Array<T>: array of the T type

extend<T> ArrayQueue<T> <: ToString where T <: ToString

extend<T> ArrayQueue<T> <: ToString where T <: ToString

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

Parent types:

func toString()

public func toString(): String

Description: Obtains the string representation of an ArrayQueue<T> instance.

The string contains the string representation of each element in the double-ended queue in sequence, for example, [elem1, elem2, elem3].

Returns:

  • String: string after conversion

class ArrayStack<T>

public class ArrayStack<T> <: Stack<T> {
    public init(capacity: Int64)
    public init()
}

Description: Specifies a stack data structure implemented based on the array. The ArrayStack is implemented by storing stack elements in an array and using a pointer to point to the position of the top element.

The ArrayStack supports only the last in first out (LIFO) mode, and allows to insert or delete elements only at the head. The ArrayStack can be expanded as required.

Parent types:

prop capacity

public prop capacity: Int64

Description: Obtains the capacity of a stack.

Type: Int64

prop size

public prop size: Int64

Description: Obtains the number of elements in a stack.

Type: Int64

func init()

public init()

Description: Constructs an empty ArrayStack with the initial capacity of 8.

func init(Int64)

public init(capacity: Int64)

Description: Constructs an empty ArrayStack with the initial capacity specified. When the value of capacity is less than the default capacity 8, the initial capacity of the constructed ArrayStack is 8.

Parameters:

  • capacity: Int64: initial capacity

Throws:

func add(T)

public func add(element: T): Unit

Description: Adds an element to the top of a stack.

Parameters:

  • element: T: element to be added

func clear()

public func clear(): Unit

Description: Clears an ArrayStack.

func isEmpty()

public func isEmpty(): Bool

Description: Checks whether an ArrayStack is empty.

Returns:

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

func iterator()

public func iterator(): Iterator<T>

Description: Returns the iterator of elements in an ArrayStack in the order of popping.

Returns:

  • Iterator<T>: iterator of elements in the stack

func peek()

public func peek(): ?T

Description: Obtains the element on the top of a stack. This operation does not pop any element and only the element on the top of the stack is viewed. If the stack is empty, None is returned.

Returns:

  • ?T: element at the top of the stack

func remove()

public func remove(): ?T

Description: Deletes the element on the top of a stack and returns the element. If the stack is empty, None is returned.

Returns:

  • ?T: top element that is deleted

func reserve(Int64)

public func reserve(additional: Int64): Unit

Description: Reserves the corresponding space for an ArrayStack. If the value of additional is less than or equal to 0, capacity expansion is not performed. If the remaining space is greater than or equal to the value of additional, capacity expansion is not performed. Otherwise, the ArrayStack capacity is expanded to the value of size plus the value of additional.

Parameters:

  • additional: Int64: remaining capacity to be reserved

func toArray()

public func toArray(): Array<T>

Description: Returns an array where the elements are those in a stack in the order of popping.

Returns:

  • Array<T>: array of the T type

extend<T> ArrayStack<T> <: ToString where T <: ToString

extend<T> ArrayStack<T> <: ToString where T <: ToString

Description: Extends the ToString interface for an ArrayStack to support string conversion.

Parent types:

func toString()

public func toString(): String

Description: Obtains the string representation of an ArrayStack<T> instance.

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

Returns:

  • String: string representation of the current stack

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 functionality of HashMap.

Parent types:

init(HashMap<K, V>)

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

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

Parameters:

func next()

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

Description: Returns the next element in the iterator.

Returns:

  • ?(K, V): next element in the iterator, which is encapsulated by using 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: Array<(K, V)>)
    public init(elements: Collection<(K, V)>)
    public init(capacity: Int64)
    public init(size: Int64, initElement: (Int64) -> (K, V))
}

Description: Implements the Map interface of a hash table.

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 the location of the element in a hash table.

A hash table features the 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 types:

prop capacity

public prop capacity: Int64

Description: Obtains the capacity of a HashMap.

Returns:

prop size

public prop size: Int64

Description: Obtains the number of key-value pairs.

Type: Int64

init()

public init()

Description: Constructs a HashMap 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 based on the passed key-value pair array.

This constructor sets the capacity of the HashMap based on the size of the passed array. Duplicate keys are not allowed in a HashMap. Therefore, when duplicate keys exist in an array, the later key-value pairs overwrite the earlier ones in the element order of the iterator.

Parameters:

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

init(Collection<(K, V)>)

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

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

This constructor sets the capacity of the HashMap based on the size of the passed collection elements. Duplicate keys are not allowed in a HashMap. Therefore, when duplicate keys exist in an array, the later key-value pairs overwrite the earlier ones in the element order of the iterator.

Parameters:

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

init(Int64)

public init(capacity: Int64)

Description: Constructs a HashMap with the 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 based on the number of passed elements specified by size and the function rule.

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

Parameters:

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

Throws:

func add(K, V)

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

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

For a key existing in the HashMap, the value of the key is replaced by the new value and the old value is returned.

Parameters:

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

Returns:

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

Examples:

For details, see Get, Add, and Contains Functions of HashMap.

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

public func add(all!: Collection<(K, V)>): Unit

Description: Puts a new key-value pair collection into a HashMap in the element order of the iterator.

For a key existing in the HashMap, the value of the key is replaced by the new value.

Parameters:

Examples:

For details, see Add, Remove, and Clear Functions of HashMap.

func addIfAbsent(K, V)

func addIfAbsent(key: K, value: V): ?V

Description: Adds a specified key-value pair if a key is not in a HashMap. Otherwise, no modification is required.

Parameters:

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

Returns:

  • ?V: If the specified key exists in the HashMap when this function is called, the old value corresponding to the key is returned. Otherwise, None is returned.

func clear()

public func clear(): Unit

Description: Clears all key-value pairs.

Examples:

For details, see Add, Remove, and Clear Functions of HashMap.

func clone()

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

Description: Clones a HashMap.

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

Examples:

For details, see Get, Add, and Contains Functions of HashMap.

func contains(Collection<K>)

public func contains(all!: 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): MapEntryView<K, V>

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

Parameters:

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

Returns:

func get(K)

public func get(key: K): ?V

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

Parameters:

  • key: K: passed key

Returns:

  • ?V: value corresponding to the key, which is encapsulated by using Option

Examples:

For details, see Get, Add, and Contains Functions of HashMap.

func isEmpty()

public func isEmpty(): Bool

Description: Checks whether a HashMap is empty. If so, true is returned. If not, false is returned.

Returns:

func iterator()

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

Description: Returns the iterator of a HashMap.

Returns:

func keys()

public func keys(): EquatableCollection<K>

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

Returns:

func remove(Collection<K>)

public func remove(all!: Collection<K>): Unit

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

Parameters:

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

func remove(K)

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

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

Parameters:

  • key: K: key to be deleted

Returns:

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

Examples:

For details, see Add, Remove, and Clear Functions of HashMap.

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 and deletes all key-value pairs that meet the condition of predicate(K, V) == true.

Parameters:

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

Throws:

func replace(K, V)

func replace(key: K, value: V): ?V

Description: Changes the value of a specified key in a HashMap to value. Otherwise, no modification is required.

Parameters:

  • key: K: key of the key-value pair to be modified
  • value: V: new value of the key-value pair to be modified

Returns:

  • ?V: If the specified key exists in the HashMap, the old value is returned. Otherwise, None is returned.

func reserve(Int64)

public func reserve(additional: Int64): Unit

Description: Expands a HashMap.

This function expands the HashMap by the value of additional. When the value of additional is less than or equal to 0, capacity expansion is not performed. When the remaining capacity of the HashMap is greater than or equal to the value of additional, capacity expansion is not performed. When the remaining capacity of the HashMap is less than the value of additional, the larger one in the value obtained after 1.5 times of the original capacity is rounded down and the value of additional plus the used capacity is used for capacity expansion.

Parameters:

  • additional: Int64: size for capacity expansion

Throws:

  • OverflowException: If the value of additional plus the used capacity exceeds the value of 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 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 and stores them in a Values container.

Returns:

operator func [](K, V)

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

Description: Overloads the add method. If a key exists, the new value overwrites the old value. If the 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: Overloads the get method. If a key exists, the value corresponding to the 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 types:

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

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

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

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

Parameters:

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

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 an instance is not equal to the HashMap<K, V> instance specified by the parameter.

Parameters:

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

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 a HashMap<K, V> to support string conversion.

Parent types:

func toString()

public func toString(): String

Description: Converts a HashMap<K, V> instance into 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 an instance of the Set interface implemented based on a HashMap.

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

NOTE

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

Parent types:

prop size

public prop size: Int64

Description: Obtains the number of elements in a HashSet.

Type: Int64

init(Int64, (Int64) -> T)

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

Description: Constructs a HashSet based on the number of passed function elements specified by size and the function rule. The capacity of the constructed HashSet is affected by the value of size.

Parameters:

  • size: Int64: number of initialization function elements
  • initElement: (Int64) ->T: initialization function rule

Throws:

init()

public init()

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

init(Array<T>)

public init(elements: Array<T>)

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

Parameters:

init(Collection<T>)

public init(elements: Collection<T>)

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

Parameters:

init(Int64)

public init(capacity: Int64)

Description: Constructs a HashSet by using a passed capacity.

Parameters:

  • capacity: Int64: initial capacity

Throws:

func add(T)

public func add(element: T): Bool

Description: Adds a specified element to a HashSet. If the element to be added exists in the HashSet, 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.

Examples:

For details, see Add, Iterator, and Remove Functions of HashSet.

func add(Collection<T>)

public func add(all!: Collection<T>): Unit

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

Parameters:

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

prop capacity

public prop capacity: Int64

Description: Obtains the internal array capacity of a HashSet.

NOTE

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

Returns:

func clear()

public func clear(): Unit

Description: Removes all elements from a HashSet.

func clone()

public func clone(): HashSet<T>

Description: Clones a HashSet.

Returns:

func contains(T)

public func contains(element: T): Bool

Description: Checks whether a HashSet contains a specified element.

Parameters:

  • element: T: specified element

Returns:

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

func contains(Collection<T>)

public func contains(all!: Collection<T>): Bool

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

Parameters:

  • all!: Collection<T>: specified element collection

Returns:

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

func isEmpty()

public func isEmpty(): Bool

Description: Checks whether a HashSet is empty.

Returns:

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

func iterator()

public func iterator(): Iterator<T>

Description: Returns the iterator of a HashSet.

Returns:

Examples:

For details, see Add, Iterator, and Remove Functions of HashSet.

func remove(T)

public func remove(element: T): Bool

Description: Removes a specified element existing in a HashSet.

Parameters:

  • element: T: element to be removed

Returns:

  • Bool: If the removal is successful, true is returned. If the removal fails, false is returned.

Examples:

For details, see Add, Iterator, and Remove Functions of HashSet.

func remove(Collection<T>)

public func remove(all!: Collection<T>): Unit

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

Parameters:

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:

func reserve(Int64)

public func reserve(additional: Int64): Unit

Description: Expands the HashSet by the value of additional. When the value of additional is less than or equal to 0, capacity expansion is not performed. When the remaining capacity of HashSet is greater than or equal to the value of additional, capacity expansion is not performed. When the remaining capacity of HashSet is less than the value of additional, the larger one in the value obtained after 1.5 times of the original capacity is rounded down and the value of additional plus the used capacity is used for capacity expansion.

Parameters:

  • additional: Int64: size for capacity expansion

Throws:

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

func retain(Set<T>)

public func retain(all!: Set<T>): Unit

Description: Retains the elements contained by a set in a HashSet.

Parameters:

  • all!: Set<T>: set whose elements are to be retained

func subsetOf(ReadOnlySet<T>)

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

Description: Checks whether a set is a subset of another ReadOnlySet.

Parameters:

  • other: ReadOnlySet<T>: set passed to determine whether it is a subset of another ReadOnlySet

Returns:

  • Bool: If the set is a subset of the specified ReadOnlySet, 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:

  • Array<T>: array of the T type

operator func &(ReadOnlySet<T>)

public operator func &(other: ReadOnlySet<T>): HashSet<T>

Description: Returns a new set containing elements that are in the intersection set of two sets.

Parameters:

Returns:

operator func |(ReadOnlySet<T>)

public operator func |(other: ReadOnlySet<T>): HashSet<T>

Description: Returns a new set containing elements that are in the union set of two sets.

Parameters:

Returns:

operator func -(ReadOnlySet<T>)

public operator func -(other: ReadOnlySet<T>): HashSet<T>

Description: Returns a new set containing elements that are in the difference set of two sets.

Parameters:

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 types:

operator func ==(HashSet<T>)

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

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

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

Parameters:

  • that: HashSet<T>: object 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 an instance is not equal to a HashSet<T> instance specified by the parameter.

Parameters:

  • that: HashSet<T>: object 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 a HashSet<T> to support string conversion.

Parent types:

func toString()

public func toString(): String

Description: Converts a HashSet<T> instance into a string.

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

Returns:

  • String: string after conversion

class LinkedListNode<T>

public class LinkedListNode<T>

Description:

Traverses forward and backward the LinkedList from the LinkedListNode, and accesses or changes element values.

The LinkedListNode can be obtained only by using the nodeAt, firstNode, and lastNode functions of the corresponding LinkedList. When the corresponding node is deleted from the LinkedList, 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 a 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 a 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 sets the value of an element.

Type: T

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: Implements a doubly linked list data structure.

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. That is, the traversal can start from the first node or the last node.

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

Parent types:

prop first

public prop first: ?T

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

Type: ?T

prop firstNode

public prop firstNode: ?LinkedListNode<T>

Description: Obtains the first node in a linked list.

Type: ?LinkedListNode<T>

prop last

public prop last: ?T

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

Type: ?T

prop lastNode

public prop lastNode: ?LinkedListNode<T>

Description: Obtains the last node in a linked list.

Type: ?LinkedListNode<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>: array of elements 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 the collection.

Parameters:

  • elements: Collection<T>: collection of elements 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 elements in the linked list to be created
  • initElement: (Int64) ->T: initialization parameter of elements

Throws:

func addLast(T)

public func addLast(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 backward(LinkedListNode<T>)

public func backward(mark: LinkedListNode<T>): Iterator<T>

Description: Obtains the iterator of all elements from the mark node to the head node of the corresponding linked list.

Parameters:

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

public func clear(): Unit

Description: Delete all elements from a linked list.

func forward(LinkedListNode<T>)

public func forward(mark: LinkedListNode<T>): Iterator<T>

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

Parameters:

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 addAfter(LinkedListNode<T>,T)

public func addAfter(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 addBefore(LinkedListNode<T>,T)

public func addBefore(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: If the linked list does not contain any element, true is returned.

func iterator()

public func iterator(): Iterator<T>

Description: Returns the iterator of elements in a collection, in the sequence from the first node to the last node in a linked list.

Returns:

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

func nodeAt(Int64)

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

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

Time complexity of this function is O(n).

Parameters:

  • index: Int64: number of the element to be obtained

Returns:

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

func removeFirst()

public func removeFirst() : ?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 removeLast()

public func removeLast() : ?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 addFirst(T)

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

Description: Inserts an element to 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 from 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 a given lambda expression or function in a linked list.

Parameters:

  • predicate: (T) ->Bool: element to be deleted. The return value is true.

Throws:

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 from a node specified by node. If the splitting is successful, node is not in the current linked list but is the first node in the new linked list.

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:

  • Array<T>: array of the T type

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 types:

operator func ==(LinkedList<T>)

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

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

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

Parameters:

  • right: LinkedList<T>: object to be compared with

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 an instance is not equal to the LinkedList<T> instance specified by the parameter.

Parameters:

  • right: LinkedList<T>: object to be compared with

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 a LinkedList<T> to support string conversion.

Parent types:

func toString()

public func toString(): String

Description: Converts the a LinkedList<T> instance into 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> <: OrderedMap<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 an instance of the OrderedMap interface implemented based on a balanced binary search tree.

This class provides an ordered key-value storage structure, which allows to quickly insert, delete, and search for elements.

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

Parent types:

prop first

public prop first: ?(K, V)

Description: Obtains the first element of a TreeMap.

Returns:

  • Option<(K, V)>: If the first element exists, the element is encapsulated by using Option and returned. Otherwise, Option<(K, V)>.None is returned.

prop last

public prop last: ?(K, V)

Description: Obtains the last element of a TreeMap.

Returns:

  • Option<(K, V)>: If the last element exists, the element is encapsulated by using Option and returned. Otherwise, Option<(K, V)>.None is returned.

prop size

public prop size: Int64

Description: Obtains the number of returned key values.

Type: Int64

init()

public init()

Description: Constructs an empty TreeMap.

init(Array<(K,V)>)

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

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

Elements are inserted into the TreeMap in the order specified in elements. Duplicate keys are not allowed in the TreeMap. If the value specified by elements contains duplicate keys, the earlier key-value pairs are overwritten by the later ones.

Parameters:

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

init(Collection<(K, V)>)

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

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

Elements are inserted into the TreeMap in the element order of the iterator. Duplicate keys are not allowed in the TreeMap. If the value specified by elements contains duplicate keys, the earlier key-value pairs (in the element order of the iterator) are overwritten by the later ones.

Parameters:

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

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

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

Description: Constructs a TreeMap based on the passed number of elements specified by size and the function rule.

Parameters:

  • size: Int64: number of passed elements
  • initElement: (Int64) -> (K, V): function rule used to initialize the TreeMap

Throws:

func add(K, V)

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

Description: Puts a new key-value pair into a TreeMap. For a key existing in the TreeMap, the value of the key is replaced by the new value.

Parameters:

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

Returns:

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

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

public func add(all!: Collection<(K, V)>): Unit

Description: Puts a new key-value pair collection into a TreeMap. For a key existing in the TreeMap, the value of the key is replaced by the new value.

Parameters:

func backward(K, Bool)

public func backward(mark: K, inclusive!: Bool = true): Iterator<(K, V)>

Description: Obtains the iterator that traverses from the first node whose key is less than or equal to mark to first in descending order. If the key of the node is equal to mark, whether the node corresponding to the key is included is determined based on inclusive!.

Parameters:

  • mark: K: key used to determine where to start
  • inclusive!: Bool: whether to include mark as the start point when mark specifies the key of the first element of the iterator. The default value is true.

Returns:

  • Iterator<(K, V)>: iterator of the corresponding element

func clear()

public func clear(): Unit

Description: Clears all key-value pairs.

func clone()

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

Description: Clones a TreeMap.

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

func contains(Collection<K>)

public func contains(all!: Collection<K>): Bool

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

Parameters:

Returns:

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

func entryView(K)

public func entryView(k: K): MapEntryView<K, V>

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

Parameters:

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

Returns:

func forward(K, Bool)

public func forward(mark: K, inclusive!: Bool = true): Iterator<(K, V)>

Description: Obtains the iterator that traverses from the first node whose key is greater than or equal to mark to last in ascending order. If the key of the node is equal to mark, whether the node corresponding to the key is included is determined based on inclusive!.

Parameters:

  • mark: K: key used to determine where to start
  • inclusive!: Bool: whether to include mark as the start point when mark specifies the key of the first element of the iterator. The default value is true.

Returns:

  • Iterator<(K, V)>: iterator of the corresponding element

func get(K)

public func get(key: K): ?V

Description: Returns the value mapped to a specified key.

Parameters:

  • key: K: specified key

Returns:

  • ?V: If there is such a value, the value is encapsulated by using Option and returned. Otherwise, Option<V>.None is returned.

func isEmpty()

public func isEmpty(): Bool

Description: Checks whether a TreeMap is empty.

Returns:

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

func iterator()

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

Description: Returns the iterator of a TreeMap, with the key values in ascending order.

Returns:

func keys()

public func keys(): EquatableCollection<K>

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

Returns:

func removeFirst()

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

Description: Deletes the first element from a TreeMap.

Returns:

  • ?(K, V): If the first element exists, the element is deleted, encapsulated by using Option, and returned. Otherwise, Option<(K, V)>.None is returned.

func removeLast()

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

Description: Deletes the last element from a TreeMap.

Returns:

  • ?(K, V): If the last element exists, the element is deleted, encapsulated by using Option, and returned. Otherwise, Option<(K, V)>.None is returned.

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 by using Option. If the specified key does not exist in the TreeMap, None is returned.

func remove(Collection<K>)

public func remove(all!: Collection<K>): Unit

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

Parameters:

  • all!: 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

Throws:

func values()

public func values(): Collection<V>

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

Returns:

operator func [](K, V)

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

Description: Overloads the indexing operator. If a key exists, the new value overwrites the old value. If the 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: Overloads the indexing operator. If a key exists, the value corresponding to the 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 types:

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

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

Description: Checks whether an instance is equal to the TreeMap<K, V> instance specified by the 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>: object to be compared with

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 an instance is not equal to the TreeMap<K, V> instance specified by the parameter.

Parameters:

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

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 a TreeMap<K, V> to support string conversion.

Parent types:

func toString()

public func toString(): String

Description: Converts a TreeMap<K, V> instance into 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

class TreeSet<T> where T <: Comparable<T>

public class TreeSet<T> <: OrderedSet<T> where T <: Comparable<T> {
    public init()
    public init(elements: Collection<T>)
    public init(size: Int64, initElement: (Int64) -> T)
}

Description: Specifies an instance of the Set interface implemented based on a TreeMap.

This class provides an ordered element storage structure, which allows to quickly insert, delete, and search for elements.

A TreeSet can be used in any scenario where ordered element storage is required, such as databases, caches, and lookup tables.

Parent types:

prop first

public prop first: ?T

Description: Obtains the first element of a TreeSet.

Type: ?T: If the first element exists, the element is encapsulated by using Option and returned. Otherwise, Option<T>.None is returned.

prop last

public prop last: ?T

Description: Obtains the last element of a TreeSet.

Type: ?T: If the last element exists, the element is encapsulated by using Option and returned. Otherwise, Option<T>.None is returned.

prop size

public prop size: Int64

Description: Obtains the number of elements.

Type: Int64

init()

public init()

Description: Constructs an empty TreeSet.

init(Collection<T>)

public init(elements: Collection<T>)

Description: Constructs a TreeSet based on the passed element collection.

Elements are inserted into the TreeSet in the element order of the iterator. The TreeSet does not allow duplicate elements. If the value specified by elements contains same elements, the TreeSet retains only one element.

Parameters:

init(Int64, (Int64) -> T)

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

Description: Constructs a TreeSet based on the passed number of elements specified by size and the function rule.

Parameters:

  • size: Int64: number of passed elements
  • initElement: (Int64) -> T: function rule used to initialize the TreeSet

Throws:

static func of(Array<T>)

public static func of(elements: Array<T>): TreeSet<T>

Description: Constructs a TreeSet that contains all elements in a specified array.

Elements are inserted into the TreeSet in the element order. The TreeSet does not allow duplicate elements. If the value specified by elements contains same elements, the TreeSet retains only one element.

Parameters:

  • elements: Array<T>: passed array

Returns:

func add(T)

public func add(element: T): Bool

Description: Adds an element to a TreeSet. If the element to be added already exists in the TreeSet, the addition fails.

Parameters:

  • element: T: specified element

Returns:

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

func add(Collection<T>)

public func add(all!: Collection<T>): Unit

Description: Adds all elements in a collection to a TreeSet. If elements to be added already exist in the latter, they are not added.

Parameters:

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

func backward(T, Bool)

public func backward(mark: T, inclusive!: Bool = true): Iterator<T>

Description: Obtains the iterator that traverses from the first node whose key is less than or equal to mark to first in descending order. If the key of the node is equal to mark, whether the node corresponding to the key is included is determined based on inclusive!.

Parameters:

  • mark: T: element used to determine where to start
  • inclusive!: Bool: whether to include mark as the start point when mark specifies the first element of the iterator. The default value is true.

Returns:

  • Iterator<T>: iterator of the corresponding elements

func clear()

public func clear(): Unit

Description: Clears all elements.

func clone()

public func clone(): TreeSet<T>

Description: Clones a TreeSet.

Returns:

func contains(T)

public func contains(element: T): Bool

Description: Checks whether a specified element is contained.

Parameters:

  • element: T: specified element

Returns:

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

func contains(Collection<T>)

public func contains(all!: Collection<T>): Bool

Description: Checks whether a TreeSet contains all elements in a specified collection.

Parameters:

  • all!: Collection<T>: specified element collection

Returns:

  • Bool: If the TreeSet contains all elements in the collection, true is returned. Otherwise, false is returned.

func forward(T, Bool)

public func forward(mark: T, inclusive!: Bool = true): Iterator<T>

Description: Obtains the iterator that traverses from the first node whose element is greater than or equal to mark to last in ascending order. If the element of the node is equal to mark, whether the node corresponding to the element is included is determined based on inclusive!.

Parameters:

  • mark: T: element used to determine where to start
  • inclusive!: Bool: whether to include mark as the start point when mark specifies the first element of the iterator. The default value is true.

Returns:

  • Iterator<T>: iterator of the corresponding elements

func isEmpty()

public func isEmpty(): Bool

Description: Checks whether a TreeSet is empty.

Returns:

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

func iterator()

public func iterator(): Iterator<T>

Description: Returns the iterator of a TreeSet, with the element values in ascending order.

Returns:

func removeFirst()

public func removeFirst(): ?T

Description: Deletes the first element from a TreeSet.

Returns:

  • ?T: If the first element exists, the element is deleted, encapsulated by using Option, and returned. Otherwise, Option<T>.None is returned.

func removeLast()

public func removeLast(): ?T

Description: Deletes the last element from a TreeSet.

Returns:

  • ?T: If the last element exists, the element is deleted, encapsulated by using Option, and returned. Otherwise, Option<T>.None is returned.

func remove(T)

public func remove(element: T): Bool

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

Parameters:

  • element: T: element to be removed

Returns:

  • Bool: If the removal is successful, true is returned. If the removal fails, false is returned.

func remove(Collection<T>)

public func remove(all!: Collection<T>): Unit

Description: Removes all elements that are also contained in a specified collection from a TreeSet.

Parameters:

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:

func retain(Set<T>)

public func retain(all!: Set<T>): Unit

Description: Retains the elements contained by a set in a TreeSet, and removes other elements.

Parameters:

  • all!: Set<T>: set whose elements are to be retained

func subsetOf(ReadOnlySet<T>)

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

Description: Checks whether a set is a subset of another ReadOnlySet.

Parameters:

  • other: ReadOnlySet<T>: set passed to determine whether it is a subset of another ReadOnlySet

Returns:

  • Bool: If the TreeSet is a subset of the specified ReadOnlySet, 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:

  • Array<T>: array of the T type

operator func &(ReadOnlySet<T>)

public operator func &(other: ReadOnlySet<T>): TreeSet<T>

Description: Returns a new set containing elements that are in the intersection set of two sets.

Parameters:

Returns:

operator func |(ReadOnlySet<T>)

public operator func |(other: ReadOnlySet<T>): TreeSet<T>

Description: Returns a new set containing elements that are in the union set of two sets.

Parameters:

Returns:

operator func -(ReadOnlySet<T>)

public operator func -(other: ReadOnlySet<T>): TreeSet<T>

Description: Returns a new set containing elements that are in the difference set of two sets.

Parameters:

Returns:

extend<T> TreeSet<T> <: Equatable<TreeSet<T>>

extend<T> TreeSet<T> <: Equatable<TreeSet<T>>

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

Parent types:

operator func ==(TreeSet<T>)

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

Description: Checks whether an instance is equal to the TreeSet<T> instance specified by the parameter.

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

Parameters:

  • that: TreeSet<T>: object to be compared with

Returns:

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

operator func !=(TreeSet<T>)

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

Description: Checks whether an instance is not equal to the TreeSet<T> instance specified by the parameter.

Parameters:

  • that: TreeSet<T>: object to be compared with

Returns:

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

extend<T> TreeSet<T> <: ToString where T <: ToString

extend<T> TreeSet<T> <: ToString where T <: ToString

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

Parent types:

func toString()

public func toString(): String

Description: Converts a TreeSet<T> instance into a string.

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

Returns:

  • String: string after conversion