Movatterモバイル変換


[0]ホーム

URL:


menu
  1. Dart
  2. dart:collection
  3. SplayTreeSet<E> class
SplayTreeSet
description

SplayTreeSet<E> classfinal

ASet of objects that can be ordered relative to each other.

The set is based on a self-balancing binary tree. It allows most operationsin amortized logarithmic time.

Elements of the set are compared using thecompare function passed inthe constructor, both for ordering and for equality.If the set contains only an objecta, thenset.contains(b)will returntrue if and only ifcompare(a, b) == 0,and the value ofa == b is not even checked.If the compare function is omitted, the objects are assumed to beComparable, and are compared using theirComparable.compareTo method.Non-comparable objects (includingnull) will not work as an elementin that case.

Note:Do not modify a set (add or remove elements) while an operationis being performed on that set, for example in functionscalled during aforEach orcontainsAll call,or while iterating the set.

Do not modify elements in a way which changes their equality (and thus theirhash code) while they are in the set. Some specialized kinds of sets may bemore permissive with regards to equality, in which case they should documenttheir different behavior and restrictions.

Example:

final planets = SplayTreeSet<String>((a, b) => a.compareTo(b));

To add data to a set, useadd oraddAll.

planets.add('Neptune');planets.addAll({'Venus', 'Mars', 'Earth', 'Jupiter'});print(planets); // {Earth, Jupiter, Mars, Neptune, Venus}

To check if the set is empty, useisEmpty orisNotEmpty.To find the number of elements in the set, uselength.

final isEmpty = planets.isEmpty; // falsefinal length = planets.length; // 5

To check whether the set contains a specific element, usecontains.

final marsExists = planets.contains('Mars'); // true

To get element value using index, useelementAt.

final elementAt = planets.elementAt(1);print(elementAt); // Jupiter

To make a copy of set, usetoSet.

final copySet = planets.toSet(); // a `SplayTreeSet` with the same ordering.print(copySet); // {Earth, Jupiter, Mars, Neptune, Venus}

To remove an element, useremove.

final removedValue = planets.remove('Mars'); // trueprint(planets); // {Earth, Jupiter, Neptune, Venus}

To remove multiple elements at the same time, useremoveWhere.

planets.removeWhere((element) => element.startsWith('J'));print(planets); // {Earth, Neptune, Venus}

To removes all elements in this set that do not meet a condition,useretainWhere.

planets.retainWhere((element) => element.contains('Earth'));print(planets); // {Earth}

To remove all elements and empty the set, useclear.

planets.clear();print(planets.isEmpty); // trueprint(planets); // {}

See also:

  • Set is a base-class for collection of objects.
  • HashSet the order of the objects in the iterations is not guaranteed.
  • LinkedHashSet objects stored based on insertion order.
Mixed-in types
Available extensions

Constructors

SplayTreeSet([intcompare(Ekey1,Ekey2)?,boolisValidKey(dynamicpotentialKey)?])
Create a newSplayTreeSet with the given compare function.
SplayTreeSet.from(Iterableelements, [intcompare(Ekey1,Ekey2)?,boolisValidKey(dynamicpotentialKey)?])
Creates aSplayTreeSet that contains allelements.
factory
SplayTreeSet.of(Iterable<E>elements, [intcompare(Ekey1,Ekey2)?,boolisValidKey(dynamicpotentialKey)?])
Creates aSplayTreeSet fromelements.
factory

Properties

first→ E
The first element.
no setteroverride
firstOrNull→ T?

Available onIterable<T>, provided by theIterableExtensions extension

The first element of this iterator, ornull if the iterable is empty.
no setter
hashCodeint
The hash code for this object.
no setterinherited
indexedIterable<(int,T)>

Available onIterable<T>, provided by theIterableExtensions extension

Pairs of elements of the indices and elements of this iterable.
no setter
isEmptybool
Whether this collection has no elements.
no setteroverride
isNotEmptybool
Whether this collection has at least one element.
no setteroverride
iteratorIterator<E>
A newIterator that allows iterating the elements of thisIterable.
no setteroverride
last→ E
The last element.
no setteroverride
lastOrNull→ T?

Available onIterable<T>, provided by theIterableExtensions extension

The last element of this iterable, ornull if the iterable is empty.
no setter
lengthint
The number of elements in thisIterable.
no setteroverride
nonNullsIterable<T>

Available onIterable<T?>, provided by theNullableIterableExtensions extension

The non-null elements of this iterable.
no setter
runtimeTypeType
A representation of the runtime type of the object.
no setterinherited
single→ E
Checks that this iterable has only one element, and returns that element.
no setteroverride
singleOrNull→ T?

Available onIterable<T>, provided by theIterableExtensions extension

The single element of this iterator, ornull.
no setter
waitFuture<List<T>>

Available onIterable<Future<T>>, provided by theFutureIterable extension

Waits for futures in parallel.
no setter

Methods

add(Eelement)bool
Addsvalue to the set.
override
addAll(Iterable<E>elements)→ void
Adds allelements to this set.
override
any(booltest(Eelement))bool
Checks whether any element of this iterable satisfiestest.
inherited
asNameMap()Map<String,T>

Available onIterable<T>, provided by theEnumByName extension

Creates a map from the names of enum values to the values.
byName(Stringname)→ T

Available onIterable<T>, provided by theEnumByName extension

Finds the enum value in this list with namename.
cast<R>()Set<R>
A view of this iterable as an iterable ofR instances.
override
clear()→ void
Removes all elements from the set.
override
contains(Object?element)bool
Whether the collection contains an element equal toelement.
override
containsAll(Iterable<Object?>other)bool
Whether this set contains all the elements ofother.
inherited
difference(Set<Object?>other)Set<E>
Creates a new set with the elements of this that are not inother.
override
elementAt(intindex)→ E
Returns theindexth element.
inherited
elementAtOrNull(intindex)→ T?

Available onIterable<T>, provided by theIterableExtensions extension

The element at positionindex of this iterable, ornull.
every(boolf(Eelement))bool
Checks whether every element of this iterable satisfiestest.
inherited
expand<T>(Iterable<T>f(Eelement))Iterable<T>
Expands each element of thisIterable into zero or more elements.
inherited
firstWhere(booltest(Evalue), {EorElse()?})→ E
The first element that satisfies the given predicatetest.
inherited
fold<T>(TinitialValue,Tcombine(TpreviousValue,Eelement))→ T
Reduces a collection to a single value by iteratively combining eachelement of the collection with an existing value
inherited
followedBy(Iterable<E>other)Iterable<E>
Creates the lazy concatenation of this iterable andother.
inherited
forEach(voidf(Eelement))→ void
Invokesaction on each element of this iterable in iteration order.
inherited
intersection(Set<Object?>other)Set<E>
Creates a new set which is the intersection between this set andother.
override
join([Stringseparator =""])String
Converts each element to aString and concatenates the strings.
inherited
lastWhere(booltest(Evalue), {EorElse()?})→ E
The last element that satisfies the given predicatetest.
inherited
lookup(Object?object)→ E?
If an object equal toobject is in the set, return it.
override
map<T>(Tf(Eelement))Iterable<T>
The current elements of this iterable modified bytoElement.
inherited
noSuchMethod(Invocationinvocation)→ dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reduce(Ecombine(Evalue,Eelement))→ E
Reduces a collection to a single value by iteratively combining elementsof the collection using the provided function.
inherited
remove(Object?object)bool
Removesvalue from the set.
override
removeAll(Iterable<Object?>elements)→ void
Removes each element ofelements from this set.
override
removeWhere(booltest(Eelement))→ void
Removes all elements of this set that satisfytest.
inherited
retainAll(Iterable<Object?>elements)→ void
Removes all elements of this set that are not elements inelements.
override
retainWhere(booltest(Eelement))→ void
Removes all elements of this set that fail to satisfytest.
inherited
singleWhere(booltest(Evalue), {EorElse()?})→ E
The single element that satisfiestest.
inherited
skip(intn)Iterable<E>
Creates anIterable that provides all but the firstcount elements.
inherited
skipWhile(booltest(Evalue))Iterable<E>
Creates anIterable that skips leading elements whiletest is satisfied.
inherited
take(intn)Iterable<E>
Creates a lazy iterable of thecount first elements of this iterable.
inherited
takeWhile(booltest(Evalue))Iterable<E>
Creates a lazy iterable of the leading elements satisfyingtest.
inherited
toList({boolgrowable =true})List<E>
Creates aList containing the elements of thisIterable.
inherited
toSet()Set<E>
Creates aSet containing the same elements as this iterable.
override
toString()String
A string representation of this object.
override
union(Set<E>other)Set<E>
Creates a new set which contains all the elements of this set andother.
override
where(boolf(Eelement))Iterable<E>
Creates a new lazyIterable with all elements that satisfy thepredicatetest.
inherited
whereType<T>()Iterable<T>
Creates a new lazyIterable with all elements that have typeT.
inherited

Operators

operator ==(Objectother)bool
The equality operator.
inherited
  1. Dart
  2. dart:collection
  3. SplayTreeSet<E> class
dart:collection library

[8]ページ先頭

©2009-2025 Movatter.jp