HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleiproute-1.7.15Haskell2010

Data.IP.RouteTable

IP routing table is a tree of IPRange to search one of them on the longest match base. It is a kind of TRIE with one way branching removed. Both IPv4 and IPv6 are supported.

For more information, see: http://www.mew.org/~kazu/proj/iproute/

  • 1 type
  • 1 class
  • 11 values
  • Packageiproute-1.7.15
  • Exports13
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceRouteTable.hs

Documentation

0 declarations

Routable class

classclass Addr a => Routable a where
#

A class to contain IPv4 and IPv6.

Methods

Instances2Routable
  • Routable IPv4Defined in iproute-1.7.15 · Data.IP.RouteTable.Internal
  • Routable IPv6Defined in iproute-1.7.15 · Data.IP.RouteTable.Internal

Type for IP routing table

datadata IPRTable k a
#

The Tree structure for IP routing table based on TRIE with one way branching removed. This is an abstract data type, so you cannot touch its inside. Please use insert or lookup, instead.

Instances11Generic1, Functor, Foldable, Traversable, Eq, Show, …

Functions to manipulate an IP routing table

valueempty :: Routable k => IPRTable k a
#

The empty function returns an empty IP routing table.

Example1 expression
(empty :: IPRTable IPv4 ()) == fromList []True
valuelookup :: Routable k => AddrRange k -> IPRTable k a -> Maybe a
#

The lookup function looks up IPRTable with a key of AddrRange. If a routing information in IPRTable matches the key, its value is returned.

Example8 expressions
let v4 = ["133.4.0.0/16","133.5.0.0/16","133.5.16.0/24","133.5.23.0/24"] :: [AddrRange IPv4]let rt = fromList $ zip v4 v4lookup "127.0.0.1" rtNothinglookup "133.3.0.1" rtNothinglookup "133.4.0.0" rtJust 133.4.0.0/16lookup "133.4.0.1" rtJust 133.4.0.0/16lookup "133.5.16.0" rtJust 133.5.16.0/24lookup "133.5.16.1" rtJust 133.5.16.0/24
valuelookupKeyValue
  1. :: Routable k
  2. => AddrRange k
  3. -> IPRTable k a
  4. -> Maybe (AddrRange k, a)
#

The lookupKeyValue function looks up IPRTable with a key of AddrRange. If a routing information in IPRTable matches the key, both key and value are returned.

Example5 expressions
:set -XOverloadedStringslet rt = fromList ([("192.168.0.0/24", 1), ("10.10.0.0/16", 2)] :: [(AddrRange IPv4, Int)])lookupKeyValue "127.0.0.1" rtNothinglookupKeyValue "192.168.0.1" rtJust (192.168.0.0/24,1)lookupKeyValue "10.10.0.1" rtJust (10.10.0.0/16,2)
valuelookupAll :: Routable k => AddrRange k -> IPRTable k a -> [(AddrRange k, a)]
#

lookupAll is a version of lookup that returns all entries matching the given key, not just the longest match.

Example5 expressions
:set -XOverloadedStringslet rt = fromList ([("192.168.0.0/24", 1), ("10.10.0.0/16", 2), ("10.0.0.0/8", 3)] :: [(AddrRange IPv4, Int)])lookupAll "127.0.0.1" rt[]lookupAll "192.168.0.1" rt[(192.168.0.0/24,1)]lookupAll "10.10.0.1" rt[(10.10.0.0/16,2),(10.0.0.0/8,3)]
valuefindMatch
  1. :: (Alternative m, Routable k)
  2. => AddrRange k
  3. -> IPRTable k a
  4. -> m (AddrRange k, a)
#

The findMatch function looks up IPRTable with a key of AddrRange. If the key matches routing informations in IPRTable, they are returned.

Example3 expressions
let v4 = ["133.4.0.0/16","133.5.0.0/16","133.5.16.0/24","133.5.23.0/24"] :: [AddrRange IPv4]let rt = fromList $ zip v4 $ repeat ()findMatch "133.4.0.0/15" rt :: [(AddrRange IPv4,())][(133.4.0.0/16,()),(133.5.0.0/16,()),(133.5.16.0/24,()),(133.5.23.0/24,())]
valuefoldlWithKey :: (b -> AddrRange k -> a -> b) -> b -> IPRTable k a -> b
#

O(n). Fold the keys and values in the IPRTable using the given left-associative binary operator. This function is equivalent to Data.Map.foldlWithKey with necessary to IPRTable changes. Since: 1.7.5

valuefoldrWithKey :: (AddrRange k -> a -> b -> b) -> b -> IPRTable k a -> b
#

O(n). Fold the keys and values in the IPRTable using the given right-associative binary operator. This function is equivalent to Data.Map.foldrWithKey with necessary to IPRTable changes. Since: 1.7.5