Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
graph-tool
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jeff Trull
graph-tool
Commits
668f14c9
Commit
668f14c9
authored
Jun 25, 2020
by
Tiago Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement equality operator for (Vertex/Edge)PropertyMap
parent
14011da1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
0 deletions
+98
-0
src/graph/graph_bind.cc
src/graph/graph_bind.cc
+9
-0
src/graph/graph_properties_copy.cc
src/graph/graph_properties_copy.cc
+30
-0
src/graph/graph_properties_copy.hh
src/graph/graph_properties_copy.hh
+43
-0
src/graph_tool/__init__.py
src/graph_tool/__init__.py
+16
-0
No files found.
src/graph/graph_bind.cc
View file @
668f14c9
...
...
@@ -440,6 +440,13 @@ void copy_external_edge_property(const GraphInterface& src,
boost
::
any
prop_src
,
boost
::
any
prop_tgt
);
bool
compare_vertex_properties
(
const
GraphInterface
&
gi
,
boost
::
any
prop1
,
boost
::
any
prop2
);
bool
compare_edge_properties
(
const
GraphInterface
&
gi
,
boost
::
any
prop1
,
boost
::
any
prop2
);
void
export_python_interface
();
void
export_openmp
();
...
...
@@ -569,6 +576,8 @@ BOOST_PYTHON_MODULE(libgraph_tool_core)
def
(
"set_vertex_property"
,
&
set_vertex_property
);
def
(
"set_edge_property"
,
&
set_edge_property
);
def
(
"copy_external_edge_property"
,
&
copy_external_edge_property
);
def
(
"compare_vertex_properties"
,
&
compare_vertex_properties
);
def
(
"compare_edge_properties"
,
&
compare_edge_properties
);
class_
<
LibInfo
>
(
"mod_info"
)
.
add_property
(
"name"
,
&
LibInfo
::
GetName
)
...
...
src/graph/graph_properties_copy.cc
View file @
668f14c9
...
...
@@ -39,3 +39,33 @@ void GraphInterface::copy_vertex_property(const GraphInterface& src,
all_graph_views
(),
all_graph_views
(),
writable_vertex_properties
())
(
this
->
get_graph_view
(),
src
.
get_graph_view
(),
prop_tgt
);
}
bool
compare_vertex_properties
(
const
GraphInterface
&
gi
,
boost
::
any
prop1
,
boost
::
any
prop2
)
{
bool
ret
=
false
;
gt_dispatch
<>
()
([
&
](
auto
&
g
,
auto
p1
,
auto
p2
)
{
ret
=
compare_props
<
vertex_selector
>
(
g
,
p1
,
p2
);
},
all_graph_views
(),
vertex_properties
(),
vertex_properties
())
(
gi
.
get_graph_view
(),
prop1
,
prop2
);
return
ret
;
}
bool
compare_edge_properties
(
const
GraphInterface
&
gi
,
boost
::
any
prop1
,
boost
::
any
prop2
)
{
bool
ret
=
false
;
gt_dispatch
<>
()
([
&
](
auto
&
g
,
auto
p1
,
auto
p2
)
{
ret
=
compare_props
<
edge_selector
>
(
g
,
p1
,
p2
);
},
all_graph_views
(),
edge_properties
(),
edge_properties
())
(
gi
.
get_graph_view
(),
prop1
,
prop2
);
return
ret
;
}
src/graph/graph_properties_copy.hh
View file @
668f14c9
...
...
@@ -21,6 +21,7 @@
#include "graph.hh"
#include "graph_filtering.hh"
#include "graph_properties.hh"
#include "graph_util.hh"
#include <boost/mpl/contains.hpp>
#include <boost/python/extract.hpp>
...
...
@@ -78,6 +79,48 @@ struct copy_property
};
template
<
class
IteratorSel
,
class
Graph
,
class
Prop1
,
class
Prop2
>
bool
compare_props
(
Graph
&
g
,
Prop1
p1
,
Prop2
p2
)
{
typedef
typename
boost
::
property_traits
<
Prop1
>::
value_type
t1
;
typedef
typename
boost
::
property_traits
<
Prop2
>::
value_type
t2
;
typename
IteratorSel
::
template
apply
<
Graph
>
::
type
vi
,
vi_end
;
std
::
tie
(
vi
,
vi_end
)
=
IteratorSel
::
range
(
g
);
try
{
for
(;
vi
!=
vi_end
;
++
vi
)
{
auto
v
=
*
vi
;
if
constexpr
(
std
::
is_same_v
<
t1
,
t2
>
)
{
if
(
p1
[
v
]
!=
p2
[
v
])
return
false
;
}
else
if
constexpr
(
std
::
is_same_v
<
t1
,
boost
::
python
::
object
>
)
{
if
(
p1
[
v
]
!=
boost
::
python
::
object
(
p2
[
v
]))
return
false
;
}
else
if
constexpr
(
std
::
is_same_v
<
t2
,
boost
::
python
::
object
>
)
{
if
(
p2
[
v
]
!=
boost
::
python
::
object
(
p1
[
v
]))
return
false
;
}
else
{
if
(
boost
::
lexical_cast
<
t1
>
(
p2
[
v
])
!=
p1
[
v
])
return
false
;
}
}
}
catch
(
boost
::
bad_lexical_cast
&
)
{
return
false
;
}
return
true
;
};
struct
edge_selector
{
template
<
class
Graph
>
...
...
src/graph_tool/__init__.py
View file @
668f14c9
...
...
@@ -855,6 +855,14 @@ class VertexPropertyMap(PropertyMap):
return
None
return
PropertyArray
(
a
,
self
)
def
__eq__
(
self
,
other
):
g
=
self
.
get_graph
()
if
g
.
base
is
not
other
.
get_graph
().
base
:
return
False
return
libcore
.
compare_vertex_properties
(
g
.
_Graph__graph
,
self
.
_get_any
(),
other
.
_get_any
())
class
EdgePropertyMap
(
PropertyMap
):
"""This class provides a mapping from edges to arbitrary properties.
...
...
@@ -889,6 +897,14 @@ class EdgePropertyMap(PropertyMap):
return
None
return
PropertyArray
(
a
,
self
)
def
__eq__
(
self
,
other
):
g
=
self
.
get_graph
()
if
g
.
base
is
not
other
.
get_graph
().
base
:
return
False
return
libcore
.
compare_edge_properties
(
g
.
_Graph__graph
,
self
.
_get_any
(),
other
.
_get_any
())
class
GraphPropertyMap
(
PropertyMap
):
"""This class provides a mapping from graphs to arbitrary properties.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment