HORIZON HASKELLDocslts/ghc-9.14.x3e2d5682026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · 3e2d568 · 2026-10-11

Modulenonempty-containers-0.3.6.0Haskell2010

Data.IntSet.NonEmpty.Internal

Unsafe internal-use functions used in the implementation of Data.IntSet.NonEmpty. These functions can potentially be used to break the abstraction of NEIntSet and produce unsound sets, so be wary!

  • 2 types
  • 11 values
datadata NEIntSet
#

A non-empty (by construction) set of integers. At least one value exists in an NEIntSet a at all times.

Functions that take an NEIntSet can safely operate on it with the assumption that it has at least one item.

Functions that return an NEIntSet provide an assurance that the result has at least one item.

Data.IntSet.NonEmpty re-exports the API of Data.IntSet, faithfully reproducing asymptotics, typeclass constraints, and semantics. Functions that ensure that input and output sets are both non-empty (like insert) return NEIntSet, but functions that might potentially return an empty map (like delete) return a IntSet instead.

You can directly construct an NEIntSet with the API from Data.IntSet.NonEmpty; it's more or less the same as constructing a normal IntSet, except you don't have access to empty. There are also a few ways to construct an NEIntSet from a IntSet:

  1. The nonEmptySet smart constructor will convert a IntSet a into a Maybe (NEIntSet a), returning Nothing if the original IntSet was empty.

  2. You can use the Data.IntSet.NonEmpty.insertIntSet family of functions to insert a value into a IntSet to create a guaranteed NEIntSet.

  3. You can use the IsNonEmpty and IsEmpty patterns to "pattern match" on a IntSet to reveal it as either containing a NEIntSet or an empty map.

  4. withNonEmpty offers a continuation-based interface for deconstructing a IntSet and treating it as if it were an NEIntSet.

You can convert an NEIntSet into a IntSet with toSet or IsNonEmpty, essentially "obscuring" the non-empty property from the type.

Constructors

Instances12IsList, Eq, Data, Ord, Read, Show, …
  • IsList NEIntSetDefined in nonempty-containers-0.3.6.0 · Data.IntSet.NonEmpty.Internal
  • Eq NEIntSetDefined in nonempty-containers-0.3.6.0 · Data.IntSet.NonEmpty.Internal
  • Data NEIntSetDefined in nonempty-containers-0.3.6.0 · Data.IntSet.NonEmpty.Internal
  • Ord NEIntSetDefined in nonempty-containers-0.3.6.0 · Data.IntSet.NonEmpty.Internal
  • Read NEIntSetDefined in nonempty-containers-0.3.6.0 · Data.IntSet.NonEmpty.Internal
  • Show NEIntSetDefined in nonempty-containers-0.3.6.0 · Data.IntSet.NonEmpty.Internal
  • Semigroup NEIntSetDefined in nonempty-containers-0.3.6.0 · Data.IntSet.NonEmpty.Internal

    Left-biased union

  • NFData NEIntSetDefined in nonempty-containers-0.3.6.0 · Data.IntSet.NonEmpty.Internal
  • FromJSON NEIntSetDefined in nonempty-containers-0.3.6.0 · Data.IntSet.NonEmpty.Internal
  • ToJSON NEIntSetDefined in nonempty-containers-0.3.6.0 · Data.IntSet.NonEmpty.Internal
  • IsNonEmptyList NEIntSetDefined in nonempty-containers-0.3.6.0 · Data.Containers.NonEmpty.List
  • type Item NEIntSet = KeyDefined in nonempty-containers-0.3.6.0 · Data.IntSet.NonEmpty.Internal

O(log n). Smart constructor for an NEIntSet from a IntSet. Returns Nothing if the IntSet was originally actually empty, and Just n with an NEIntSet, if the IntSet was not empty.

nonEmptySet and maybe empty toSet form an isomorphism: they are perfect structure-preserving inverses of eachother.

See IsNonEmpty for a pattern synonym that lets you "match on" the possiblity of a IntSet being an NEIntSet.

nonEmptySet (Data.IntSet.fromList [3,5]) == Just (fromList (3:|[5]))
valuetoSet :: NEIntSet -> IntSet
#

O(log n). Convert a non-empty set back into a normal possibly-empty map, for usage with functions that expect IntSet.

Can be thought of as "obscuring" the non-emptiness of the set in its type. See the Data.IntSet.NonEmpty.IsNotEmpty pattern.

nonEmptySet and maybe empty toSet form an isomorphism: they are perfect structure-preserving inverses of eachother.

toSet (fromList ((3,"a") :| [(5,"b")])) == Data.IntSet.fromList [(3,"a"), (5,"b")]
valueunion :: NEIntSet -> NEIntSet -> NEIntSet
#

O(m*log(n/m + 1)), m <= n. The union of two sets, preferring the first set when equal elements are encountered.

valueinsertMinSet :: Key -> IntSet -> IntSet
#

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 IntSet. /The precondition is not checked./

At the moment this is simply an alias for Data.IntSet.insert, but it's left here as a placeholder in case this eventually gets implemented in a more efficient way.

valueinsertMaxSet :: Key -> IntSet -> IntSet
#

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 IntSet. The precondition is not checked./

At the moment this is simply an alias for Data.IntSet.insert, but it's left here as a placeholder in case this eventually gets implemented in a more efficient way.