Opened 15 years ago
Closed 15 years ago
#320 closed enhancement (done)
Map utilities
Reported by: | Peter Kovacs | Owned by: | Peter Kovacs |
---|---|---|---|
Priority: | major | Milestone: | LEMON 1.2 release |
Component: | core | Version: | hg main |
Keywords: | Cc: | ||
Revision id: |
Description
It would be nice to have some functions to make it easier to work with graph maps.
I could imagine the following functions (similarly to STL tools in <algorithm>
). Let K
and V
denote the Key
and Value
type of Map
.
K mapMin(Map)
,K mapMin(Map, Comp)
K mapMax(Map)
,K mapMax(Map, Comp)
V mapMinValue(Map)
,V mapMinValue(Map, Comp)
V mapMaxValue(Map)
,V mapMaxValue(Map, Comp)
K mapFind(Map, V)
,K mapFindIf(Map, Cond)
int mapCount(Map, V)
,int mapCountIf(Map, Cond)
void mapFill(Map, V)
void mapReplace(Map, V, V)
bool mapCompare(Map1, Map2)
void mapCopy(Map1, Map2)
(see also #146)
- And maybe:
V mapSum(Map)
,V mapSum(Map, V init)
Some of these names could be misleading, e.g. mapReplace
or mapCount
, since they operate on map values, not maps. On the other hand, mapCompare
and mapCopy
would operate on maps.
Since the standard graph maps have iterator classes to traverse the corresponding item set, these functions could be implemented easily. However if we would like to support all maps whose key type is the Node
, Arc
or Edge
type of graph, than we should provide overloaded versions that take the graph as well, e.g. mapMin(Map, Graph)
. But it could be confusing if we also have mapMin(Map, Comp)
and mapMin(Map, Graph, Comp)
.
Attachments (1)
Change History (10)
comment:1 Changed 15 years ago by
comment:2 Changed 15 years ago by
What do you think? Could you help me make a decision about these function names (and interface)?
Changed 15 years ago by
Attachment: | 320-maputils-8ddb7deabab9.patch added |
---|
comment:3 follow-up: 4 Changed 15 years ago by
Status: | new → assigned |
---|
I attached a changeset [8ddb7deabab9] introducing these utilities. I omitted mapSum()
and mapSetAll()
since they not seemed so fundamental as the others.
Note that the STL algorithms that operate on ranges can also be applied to standard graph maps using their MapIt
or ConstMapIt
iterators, though it is not so convenient. E.g.
typedef SmartDigraph::NodeMap<int>::ConstMapIt MapIt; Map map(g); for_each(MapIt(map), MapIt(INVALID), action_functor);
It is also tested in map_test.cc
, but the bugfix in #330 is required for this. Thus, if it is also merged, these parts of the test file can be "turned on".
comment:4 Changed 15 years ago by
Replying to kpeter:
I attached a changeset [8ddb7deabab9] introducing these utilities.
It went to the main branch.
I omitted
mapSum()
andmapSetAll()
since they not seemed so fundamental as the others.
I made a mistake here. Correctly: I omitted mapSum()
and mapReplace()
, since they not seemed so fundamental as the others.
I think, the only questionable name is mapFill
. It is analogous to std::fill
. On the other hand, we have set()
functions for all writable maps, and some of them also has setAll()
. Thus mapSetAll()
would also be a logical name for this global function. What do you think?
comment:6 follow-up: 7 Changed 15 years ago by
Replying to alpar:
Is there anything to do here?
As I wrote:
I think, the only questionable name is mapFill. It is analogous to std::fill. On the other hand, we have set() functions for all writable maps, and some of them also has setAll(). Thus mapSetAll() would also be a logical name for this global function. What do you think?
comment:7 follow-up: 8 Changed 15 years ago by
Replying to kpeter:
Replying to alpar:
Is there anything to do here?
As I wrote:
I think, the only questionable name is mapFill. It is analogous to std::fill. On the other hand, we have set() functions for all writable maps, and some of them also has setAll(). Thus mapSetAll() would also be a logical name for this global function. What do you think?
I don't care.
comment:9 Changed 15 years ago by
Resolution: | → done |
---|---|
Status: | assigned → closed |
Replying to kpeter:
It does not seem a significant disadvantage to only have common interfaces including the graph as a parameter.
Thus I suggest the following functions:
K mapMin(Graph, Map)
,K mapMin(Graph, Map, Comp)
K mapMax(Graph, Map)
,K mapMax(Graph, Map, Comp)
V mapMinValue(Graph, Map)
,V mapMinValue(Graph, Map, Comp)
V mapMaxValue(Graph, Map)
,V mapMaxValue(Graph, Map, Comp)
K mapFind(Graph, Map, V)
,K mapFindIf(Graph, Map, Cond)
int mapCount(Graph, Map, V)
,int mapCountIf(Graph, Map, Cond)
void mapFill(Graph, Map, V)
void mapReplace(Graph, Map, V, V)
bool mapCompare(Graph, Map1, Map2)
void mapCopy(Graph, Map1, Map2)
(see also #146)V mapSum(Graph, Map)
,V mapSum(Graph, Map, V init)