目录

接口

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

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

功能:定义了可以进行比较的集合类型。

[h2]func contains(T)

func contains(element: T): Bool

功能:判断 Keys 是否包含指定元素。

参数:

返回值:

[h2]func containsAll(Collection<T>)

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

功能:判断 Keys 是否包含指定集合的所有元素。

参数:

返回值:

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

功能:Map 接口提供了一种将键映射到值的方式。它允许我们使用键来查找值,因此可以用于存储和操作键值对。

map不能包含重复的key,每个key最多只能映射到一个value。

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

[h2]prop size

prop size: Int64

功能:返回 Map 中所有的键值对的个数。

类型:Int64

[h2]func clear()

mut func clear(): Unit

功能:清除所有键值对。

[h2]func clone()

func clone(): Map<K, V>

功能:克隆 Map。

返回值:

[h2]func contains(K)

func contains(key: K): Bool

功能:判断是否包含指定键的映射。

参数:

返回值:

[h2]func containsAll(Collection<K>)

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

功能:判断是否包含指定集合键的映射。

参数:

返回值:

[h2]func get(K)

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

功能:根据 key 得到 Map 中映射的值。

参数:

返回值:

[h2]func isEmpty()

func isEmpty(): Bool

功能:检查 Map 是否为空。

返回值:

[h2]func iterator()

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

功能:返回 Map 的迭代器。

返回值:

[h2]func keys()

func keys(): EquatableCollection<K>

功能:返回 Map 中所有的 key,并将所有 key 存储在一个 EquatableCollection<K> 容器中。

返回值:

[h2]func put(K, V)

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

功能:将传入的键值对放入该 Map 中。对于 Map 中已有的键,该键映射的值将被新值替换。

参数:

返回值:

[h2]func putAll(Collection<(K, V)>)

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

功能:将新的键值对放入 Map 中。对于 Map 中已有的键,该键映射的值将被新值替换。

参数:

[h2]func remove(K)

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

功能:从此 Map 中删除指定键的映射(如果存在)。

参数:

返回值:

[h2]func removeAll(Collection<K>)

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

功能:从此映射中删除指定集合的映射(如果存在)。

参数:

[h2]func removeIf((K, V) -> Bool)

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

功能:传入 lambda 表达式,如果满足条件,则删除对应的键值对。

参数:

[h2]func values()

func values(): Collection<V>

功能:返回 Map 中所有的 value,并将所有 value 存储在一个 Collection<V> 容器中。

返回值:

[h2]operator func [](K)

operator func [](key: K): V

功能:运算符重载集合,如果键存在,返回键对应的值,如果不存在,抛出异常。

参数:

返回值:

[h2]operator func [](K, V)

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

功能:运算符重载集合,如果键存在,新 value 覆盖旧 value,如果键不存在,添加此键值对。

参数:

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

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

功能:不包含重复元素的集合。

Set 接口不规定内部的实现方式,在 Set 接口的实例中,其内部的元素通常是无序的,不能通过索引访问,也不能保证元素的插入顺序。

[h2]func clear()

mut func clear(): Unit

功能:清除所有键值对。

[h2]func clone()

func clone(): Set<T>

功能:克隆此 Set,并返回克隆出的新的 Set。

返回值:

[h2]func contains(T)

func contains(element: T): Bool

功能:如果该集合包含指定元素,则返回 true。

参数:

返回值:

[h2]func containsAll(Collection<T>)

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

功能:检查该集合是否包含其他集合。

参数:

返回值:

[h2]func put(T)

mut func put(element: T): Bool

功能:添加元素操作。如果元素已经存在,则不会添加它。

参数:

返回值:

[h2]func putAll(Collection<T>)

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

功能:添加 Collection 中的所有元素至此 Set 中,如果元素存在,则不添加。

参数:

[h2]func remove(T)

mut func remove(element: T): Bool

功能:从该集合中移除指定元素(如果存在)。

参数:

返回值:

[h2]func removeAll(Collection<T>)

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

功能:移除此 Set 中那些也包含在指定 Collection 中的所有元素。

参数:

[h2]func removeIf((T) -> Bool)

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

功能:传入 lambda 表达式,如果满足 true 条件,则删除对应的元素。

参数:

[h2]func retainAll(Set<T>)

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

功能:仅保留该 Set 与入参 Set 中重复的元素。

参数:

[h2]func subsetOf(Set<T>)

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

功能:检查该集合是否为其他集合的子集。

参数:

返回值: