Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
libcifpp
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
libcifpp
Commits
0c70df27
Unverified
Commit
0c70df27
authored
Dec 13, 2022
by
Maarten L. Hekkelman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimised erase
parent
d83f3472
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
20 deletions
+32
-20
src/category.cpp
+32
-20
No files found.
src/category.cpp
View file @
0c70df27
...
...
@@ -1142,10 +1142,6 @@ category::iterator category::erase(iterator pos)
row
*
r
=
rh
.
get_row
();
iterator
result
=
++
pos
;
iset
keys
;
if
(
m_cat_validator
)
keys
=
iset
(
m_cat_validator
->
m_keys
.
begin
(),
m_cat_validator
->
m_keys
.
end
());
if
(
m_head
==
nullptr
)
throw
std
::
runtime_error
(
"erase"
);
...
...
@@ -1174,7 +1170,7 @@ category::iterator category::erase(iterator pos)
// in mmcif_pdbx.dic dictionary.
//
// For each link group in _pdbx_item_linked_group_list
// a s
td::s
et of keys from one category is mapped to another.
// a set of keys from one category is mapped to another.
// If all values in a child are the same as the specified parent ones
// the child is removed as well, recursively of course.
...
...
@@ -1198,25 +1194,29 @@ category::iterator category::erase(iterator pos)
return
result
;
}
size_t
category
::
erase
(
condition
&&
cond
)
template
<
typename
T
>
class
save_value
{
size_t
result
=
0
;
cond
.
prepare
(
*
this
);
public
:
save_value
(
T
&
v
,
const
T
nv
=
{})
:
m_v
(
v
)
,
m_sv
(
std
::
exchange
(
m_v
,
nv
))
{
}
auto
ri
=
begin
();
while
(
ri
!=
end
())
~
save_value
()
{
if
(
cond
(
*
ri
))
{
ri
=
erase
(
ri
);
++
result
;
}
else
++
ri
;
m_v
=
m_sv
;
}
return
result
;
private
:
T
&
m_v
;
const
T
m_sv
;
};
size_t
category
::
erase
(
condition
&&
cond
)
{
return
erase
(
std
::
move
(
cond
),
{});
}
size_t
category
::
erase
(
condition
&&
cond
,
std
::
function
<
void
(
row_handle
)
>
&&
visit
)
...
...
@@ -1225,12 +1225,21 @@ size_t category::erase(condition &&cond, std::function<void(row_handle)> &&visit
cond
.
prepare
(
*
this
);
std
::
map
<
category
*
,
condition
>
potential_orphans
;
auto
ri
=
begin
();
while
(
ri
!=
end
())
{
if
(
cond
(
*
ri
))
{
visit
(
*
ri
);
if
(
visit
)
visit
(
*
ri
);
for
(
auto
&&
[
childCat
,
link
]
:
m_child_links
)
potential_orphans
[
childCat
]
=
std
::
move
(
potential_orphans
[
childCat
])
or
get_children_condition
(
*
ri
,
*
childCat
);
save_value
sv
(
m_validator
);
ri
=
erase
(
ri
);
++
result
;
}
...
...
@@ -1238,6 +1247,9 @@ size_t category::erase(condition &&cond, std::function<void(row_handle)> &&visit
++
ri
;
}
for
(
auto
&&
[
childCat
,
condition
]
:
potential_orphans
)
childCat
->
erase_orphans
(
std
::
move
(
condition
),
*
this
);
return
result
;
}
...
...
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