module Tables2(DTable(..), dtable0, lookupDe, listDe, updateDe) where
import Utils(pair)
--import Direction() -- instances, for hbc
import Path(Path(..))
import Sockets(Descriptor)
import Table

type DTable = Table Descriptor Path

updateDe :: Path -> [Descriptor] -> DTable -> DTable
updateDe :: Path -> [Descriptor] -> DTable -> DTable
updateDe Path
path' [Descriptor]
ds DTable
dtable =
    forall {k} {v}. Ord k => [(k, v)] -> Table k v
table (forall a b. (a -> b) -> [a] -> [b]
map (forall {a} {b}. a -> b -> (a, b)
`pair` Path
path') [Descriptor]
ds forall a. [a] -> [a] -> [a]
++
           forall a. (a -> Bool) -> [a] -> [a]
filter ((forall a. Eq a => a -> a -> Bool
/= Path
path') forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) (forall {k} {v}. Table k v -> [(k, v)]
listTable DTable
dtable))

listDe :: DTable -> [Descriptor]
listDe :: DTable -> [Descriptor]
listDe DTable
dtable = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst (forall {k} {v}. Table k v -> [(k, v)]
listTable DTable
dtable)

lookupDe :: DTable -> Descriptor -> Path
lookupDe :: DTable -> Descriptor -> Path
lookupDe DTable
dtable Descriptor
de =
    forall {a} {t3} {b}.
Ord a =>
t3 -> ((a, b) -> t3) -> a -> Table a b -> t3
tableLookup (forall a. HasCallStack => [Char] -> a
error ([Char]
"Descriptor without path: "forall a. [a] -> [a] -> [a]
++forall a. Show a => a -> [Char]
show Descriptor
de)) forall a b. (a, b) -> b
snd Descriptor
de DTable
dtable

dtable0 :: DTable
dtable0 :: DTable
dtable0 = forall {k} {v}. Ord k => [(k, v)] -> Table k v
table []