haskell / fgl

A Functional Graph Library for Haskell
http://hackage.haskell.org/package/fgl
Other
184 stars 54 forks source link

Introduce lookup options when inserting node in a NodeMap #77

Closed nobrakal closed 10 months ago

nobrakal commented 6 years ago

This is a try to fix #72 .

The main new function is mkLookupNode, which is mkNode plus a Boolean saying if the node was already present.

I also added a member-like function.

ivan-m commented 6 years ago

I'm wondering whether it might be worth defining a new type isomorphic to Bool to make it clear what the result it (does True mean "added in" or "already present"?).

nobrakal commented 6 years ago

It might worth it, you are right. Seems a bit overkill for two functions. I don't know if lookup counter-part functions can be made/are interesting in NodeMap

I am also wondering if a direct lookup version of insNode and maybe insEdge were interesting in the Graph module... They can be easily optimized in PatriciaTree

runeksvendsen commented 5 years ago

Is there anything preventing this from being pulled? I'm looking for this exact functionality.

runeksvendsen commented 5 years ago

The only thing I'd like to add is that -- while we're at it -- it would be nice to also have the corresponding monadic versions of e.g. lookupNode:

lookupNodeM :: (Ord a) => a -> NodeMapM a b g (Maybe Node).

cdupont commented 3 years ago

I also need this function :)

athas commented 2 years ago

Is there still interest in this functionality? If so, I will merge this PR.

Montmorency commented 10 months ago

This is useful for quickly getting nodes from the label set.