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

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Modulebytestring-trie-0.2.7.7Haskell2010

Data.Trie.Convenience

Additional convenience functions. In order to keep Data.Trie concise, non-essential and uncommonly used functions have been moved here. Most of these functions simplify the generic functions from Data.Trie, following after the interface for Data.Map and Data.IntMap.

  • 21 values

Conversion functions (fromList variants)

7 declarations

Just like fromList all of these functions convert an association list into a trie, with earlier values shadowing later ones when keys conflict. Depending on the order of keys in the list, there can be as much as 5x speed difference between the left and right variants. Yet, performance is about the same when matching best-case to best-case and worst-case to worst-case (which is which is swapped when reversing the list or changing which function is used).

valuefromListS :: [(ByteString, a)] -> Trie a
#

This variant sorts the list before folding over it. This adds \mathcal{O}(n \log n) overhead and requires the whole list be in memory at once, but it ensures that the list is in best-case order. The benefits generally outweigh the costs.

valuefromListWith :: (a -> a -> a) -> [(ByteString, a)] -> Trie a
#

A variant of fromListR that takes a function for combining values on conflict. The first argument to the combining function is the "new" value from the initial portion of the list; the second argument is the value that has been accumulated into the trie from the tail of the list (just like the first argument to foldr). Thus, fromList = fromListWith const.

valuefromListWith' :: (a -> a -> a) -> [(ByteString, a)] -> Trie a
#

A variant of fromListWith which applies the combining function strictly. This function is a good consumer for list fusion. If you need list fusion and are running into stack overflow problems with fromListWith, then this function may solve the problem.

valuefromListWithL :: (a -> a -> a) -> [(ByteString, a)] -> Trie a
#

A left-fold variant of fromListWith. Note that the arguments to the combining function are swapped: the first is the value in the trie which has been accumulated from the initial part of the list; the second argument is the "new" value from the remaining tail of the list (just like the first argument to foldl). Thus, fromListL = fromListWithL const.

Query functions (lookupBy variants)

1 declaration

Inserting values (alterBy variants)

5 declarations

Updating and adjusting values (alterBy and adjustBy variants)

3 declarations

Combining tries (mergeBy and intersectBy variants)

5 declarations
valuedisunion :: Trie a -> Trie a -> Trie a
#

Combine two tries, a la symmetric difference. If they define the same key, it is removed; otherwise it is retained with the value it has in whichever trie.

valueunionWith :: (a -> a -> a) -> Trie a -> Trie a -> Trie a
#

Take the union of two tries, using a function to resolve conflicts. The resulting trie is constructed strictly, but the results of the combining function are evaluated lazily.

valueintersectWith :: (a -> b -> c) -> Trie a -> Trie b -> Trie c
#

Take the intersection of two tries, with a function to resolve the values. The resulting trie is constructed strictly, bit the results of the combining function are evaluated lazily.