Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
e0153068
Commit
e0153068
authored
Aug 07, 2018
by
Tiago Peixoto
Browse files
Implement ProperyMap.swap()
parent
dd46ba20
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/graph/fast_vector_property_map.hh
View file @
e0153068
...
...
@@ -112,6 +112,11 @@ public:
std
::
vector
<
T
>&
get_storage
()
const
{
return
(
*
store
);
}
void
swap
(
checked_vector_property_map
&
other
)
{
store
->
swap
(
*
other
.
store
);
}
unchecked_t
get_unchecked
(
size_t
size
=
0
)
const
{
reserve
(
size
);
...
...
@@ -183,23 +188,26 @@ public:
void
resize
(
size_t
size
)
const
{
_checked
.
resize
(
size
);
}
void
shrink_to_fit
()
const
{
_checked
.
shrink_to_fit
();
}
__attribute__
((
always_inline
))
__attribute__
((
flatten
))
reference
operator
[](
const
key_type
&
v
)
const
{
auto
i
=
get
(
_checked
.
index
,
v
);
return
(
*
_checked
.
store
)[
i
];
return
(
*
_checked
.
store
)[
get
(
_checked
.
index
,
v
)];
}
std
::
vector
<
T
>&
get_storage
()
const
{
return
_checked
.
get_storage
();
}
void
swap
(
unchecked_vector_property_map
&
other
)
{
get_storage
().
swap
(
other
.
get_storage
());
}
checked_t
get_checked
()
{
return
_checked
;}
// deep copy
unchecked_vector_property_map
copy
()
const
{
unchecked_vector_property_map
pmap
(
_checked
.
index
,
_checked
.
store
->
size
());
*
(
pmap
.
_checked
.
store
)
=
*
(
_checked
.
store
);
return
pmap
;
return
_checked
.
copy
().
get_unchecked
();
}
private:
...
...
src/graph/graph_python_interface.hh
View file @
e0153068
...
...
@@ -603,6 +603,23 @@ public:
{
}
void
swap
(
PythonPropertyMap
&
other
)
{
swap_dispatch
(
other
,
std
::
is_convertible
<
typename
boost
::
property_traits
<
PropertyMap
>::
category
,
boost
::
writable_property_map_tag
>
());
}
void
swap_dispatch
(
PythonPropertyMap
&
other
,
std
::
true_type
)
{
_pmap
.
swap
(
other
.
_pmap
);
}
void
swap_dispatch
(
PythonPropertyMap
&
other
,
std
::
false_type
)
{
throw
ValueException
(
"Read-only property map cannot be swapped."
);
}
size_t
data_ptr
()
{
typename
boost
::
mpl
::
or_
<
...
...
src/graph/graph_python_interface_export.cc
View file @
e0153068
...
...
@@ -66,6 +66,7 @@ struct export_vertex_property_map
.
def
(
"reserve"
,
&
pmap_t
::
reserve
)
.
def
(
"resize"
,
&
pmap_t
::
resize
)
.
def
(
"shrink_to_fit"
,
&
pmap_t
::
shrink_to_fit
)
.
def
(
"swap"
,
&
pmap_t
::
swap
)
.
def
(
"data_ptr"
,
&
pmap_t
::
data_ptr
);
typedef
boost
::
mpl
::
transform
<
graph_tool
::
all_graph_views
,
...
...
@@ -149,6 +150,7 @@ struct export_edge_property_map
.
def
(
"reserve"
,
&
pmap_t
::
reserve
)
.
def
(
"resize"
,
&
pmap_t
::
resize
)
.
def
(
"shrink_to_fit"
,
&
pmap_t
::
shrink_to_fit
)
.
def
(
"swap"
,
&
pmap_t
::
swap
)
.
def
(
"data_ptr"
,
&
pmap_t
::
data_ptr
);
...
...
src/graph_tool/__init__.py
View file @
e0153068
...
...
@@ -830,6 +830,14 @@ class PropertyMap(object):
self
.
__map
.
resize
(
size
)
self
.
__map
.
shrink_to_fit
()
def
swap
(
self
,
other
):
"""Swap internal storage with ``other``."""
if
self
.
key_type
()
!=
other
.
key_type
():
raise
ValueError
(
"property maps must have the same key type"
)
if
self
.
value_type
()
!=
other
.
value_type
():
raise
ValueError
(
"property maps must have the same value type"
)
self
.
__map
.
swap
(
other
.
__map
)
def
data_ptr
(
self
):
"""Return the pointer to memory where the data resides."""
return
self
.
__map
.
data_ptr
()
...
...
Write
Preview
Supports
Markdown
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