public interface EquatableCollection<T> <: Collection<T> where T <: Equatable<T> {
func contains(element: T): Bool
func containsAll(elements: Collection<T>): Bool
} 功能:定义了可以进行比较的集合类型。
func contains(element: T): Bool
功能:判断 Keys 是否包含指定元素。
参数:
返回值:
func containsAll(elements: Collection<T>): Bool
功能:判断 Keys 是否包含指定集合的所有元素。
参数:
返回值:
功能: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)>
} func contains(key: K): Bool
功能:判断是否包含指定键的映射。
参数:
返回值:
func containsAll(keys: Collection<K>): Bool
功能:判断是否包含指定集合键的映射。
参数:
返回值:
func get(key: K): Option<V>
功能:根据 key 得到 Map 中映射的值。
参数:
返回值:
func keys(): EquatableCollection<K>
功能:返回 Map 中所有的 key,并将所有 key 存储在一个 EquatableCollection<K> 容器中。
返回值:
mut func put(key: K, value: V): Option<V>
功能:将传入的键值对放入该 Map 中。对于 Map 中已有的键,该键映射的值将被新值替换。
参数:
返回值:
mut func putAll(elements: Collection<(K, V)>): Unit
功能:将新的键值对放入 Map 中。对于 Map 中已有的键,该键映射的值将被新值替换。
参数:
mut func remove(key: K): Option<V>
功能:从此 Map 中删除指定键的映射(如果存在)。
参数:
返回值:
mut func removeAll(keys: Collection<K>): Unit
功能:从此映射中删除指定集合的映射(如果存在)。
参数:
mut func removeIf(predicate: (K, V) -> Bool): Unit
功能:传入 lambda 表达式,如果满足条件,则删除对应的键值对。
参数:
func values(): Collection<V>
功能:返回 Map 中所有的 value,并将所有 value 存储在一个 Collection<V> 容器中。
返回值:
operator func [](key: K): V
功能:运算符重载集合,如果键存在,返回键对应的值,如果不存在,抛出异常。
参数:
返回值:
operator func [](key: K, value!: V): Unit
功能:运算符重载集合,如果键存在,新 value 覆盖旧 value,如果键不存在,添加此键值对。
参数:
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 接口的实例中,其内部的元素通常是无序的,不能通过索引访问,也不能保证元素的插入顺序。
func contains(element: T): Bool
功能:如果该集合包含指定元素,则返回 true。
参数:
返回值:
func containsAll(elements: Collection<T>): Bool
功能:检查该集合是否包含其他集合。
参数:
返回值:
mut func put(element: T): Bool
功能:添加元素操作。如果元素已经存在,则不会添加它。
参数:
返回值:
mut func putAll(elements: Collection<T>): Unit
功能:添加 Collection 中的所有元素至此 Set 中,如果元素存在,则不添加。
参数:
mut func remove(element: T): Bool
功能:从该集合中移除指定元素(如果存在)。
参数:
返回值:
mut func removeAll(elements: Collection<T>): Unit
功能:移除此 Set 中那些也包含在指定 Collection 中的所有元素。
参数:
mut func removeIf(predicate: (T) -> Bool): Unit
功能:传入 lambda 表达式,如果满足 true 条件,则删除对应的元素。
参数:
mut func retainAll(elements: Set<T>): Unit
参数: