insert module:Data.Set -is:exact -package:linear-base -package:multimap -package:set-monad
Insert an element in a set. If the set already contains
an element equal to the given value, it is replaced with the new
value.
O(log n). Insert an element in a set. If the set already
contains an element equal to the given value, it is replaced with the
new value.
O(log n). Convert a
Set into an
NESet by adding a
value. Because of this, we know that the set must have at least one
element, and so therefore cannot be empty.
See
insertSetMin for a version that is constant-time if the new
value is
strictly smaller than all values in the original set
insertSet 4 (Data.Set.fromList [5, 3]) == fromList (3 :| [4, 5])
insertSet 4 Data.Set.empty == singleton 4 "c"
O(log n) Convert a
Set into an
NESet by adding a
value where the value is
strictly less than all values in the
input set The values in the original map must all be
strictly
greater than the new value.
The precondition is not
checked.
While this has the same asymptotics as
insertSet, it saves a
constant factor for key comparison (so may be helpful if comparison is
expensive) and also does not require an
Ord instance for the
key type.
insertSetMin 7 (Data.Set.fromList [5, 3]) == fromList (3 :| [5, 7])
valid (insertSetMin 7 (Data.Set.fromList [5, 3])) == True
valid (insertSetMin 2 (Data.Set.fromList [5, 3])) == False
valid (insertSetMin 5 (Data.Set.fromList [5, 3])) == False
O(1) Convert a
Set into an
NESet by adding a
value where the value is
strictly less than all values in the
input set The values in the original map must all be
strictly
greater than the new value.
The precondition is not
checked.
insertSetMin 2 (Data.Set.fromList [5, 3]) == fromList (2 :| [3, 5])
valid (insertSetMin 2 (Data.Set.fromList [5, 3])) == True
valid (insertSetMin 7 (Data.Set.fromList [5, 3])) == False
valid (insertSetMin 3 (Data.Set.fromList [5, 3])) == False
O(log n). Insert new value into a set where values are
/strictly less than
the new value. That is, the new value must be
strictly greater than
all values present in the Set.
The precondition is not checked./
While this has the same asymptotics as
Data.Set.insert, it
saves a constant factor for value comparison (so may be helpful if
comparison is expensive) and also does not require an
Ord
instance for the value type.
O(log n). Insert new value into a set where values are
strictly greater than the new values That is, the new value
must be
strictly less than all values present in the
Set. /The precondition is not checked./
While this has the same asymptotics as
Data.Set.insert, it
saves a constant factor for value comparison (so may be helpful if
comparison is expensive) and also does not require an
Ord
instance for the value type.