module Tables2(DTable(..), dtable0, lookupDe, listDe, subDes, updateDe) where import Data.List(partition) import Utils(pair) --import Direction() -- instances, for hbc import Path(Path,subPath) import Sockets(Descriptor) import Table type DTable = Table Descriptor Path updateDe :: Path -> [Descriptor] -> DTable -> DTable updateDe path' ds dtable = table (map (`pair` path') ds ++ filter ((/= path') . snd) (listTable dtable)) listDe :: DTable -> [Descriptor] listDe dtable = map fst (listTable dtable) --findDe :: DTable -> Path -> [Descriptor] --findDe dtable path = [de | (de,path') <- listTable dtable, path'==path] subDes :: DTable -> Path -> ([Descriptor],DTable) subDes dtable path = (map fst children,table other) where (children,other) = partition (subPath path.snd) (listTable dtable) lookupDe :: DTable -> Descriptor -> Path lookupDe dtable de = tableLookup (error ("Descriptor without path: "++show de)) snd de dtable dtable0 :: DTable dtable0 = table []