@@ -70,6 +70,11 @@ class OrderedSet(MutableSet[T], Sequence[T]):
7070 because [`OrderedSet.append`] ignores duplicate elements
7171 and returns `bool` instead of `None`.
7272
73+ The [`OrderedSet.remove`] method takes linear time to remove an element,
74+ not constant time like `set.remove` does.
75+ Calling it in a loop will trigger quadratic blow up just like use of [`list.remove`] would.
76+ To avoid this, bulk-remove elements using the set subtraction operator (`-=`).
77+
7378 ### Thread Safety
7479 This type is *NOT* safe to mutate from multiple threads.
7580
@@ -167,6 +172,11 @@ def remove(self, value: T, /) -> None:
167172 """
168173 Remove an element from the set, throwing a KeyError if not present.
169174
175+ This method preserves the original order of the set.
176+ However, it takes linear time like [`list.remove`],
177+ instead of the constant time that [`set.remove`] takes.
178+ Invoking it repeatedly may cause quadratic blowup, just like `list.remove` would.
179+
170180 See [`OrderedSet.discard`] for a variant that does nothing if the item is not present.
171181 """
172182 # set.remove will raise a KeyError for us
@@ -178,6 +188,11 @@ def discard(self, value: T, /) -> None:
178188 """
179189 Remove an element from the set if it exists.
180190
191+ This method preserves the original order of the set.
192+ However, it takes linear time (`O(n)`) instead of the constant time.
193+ Invoking it repeatedly may cause quadratic blowup.
194+ See [`OrderedSet.remove`] for more details on this.
195+
181196 Unlike [`OrderedSet.remove`], this method does not raise
182197 an exception if this element is missing.
183198 """
0 commit comments