Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
athena
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Peter Sherwood
athena
Commits
2a5819fb
Verified
Commit
2a5819fb
authored
4 years ago
by
Adam Edward Barton
Browse files
Options
Downloads
Patches
Plain Diff
Change the boolean mask to a set for faster iteration
parent
8378a05f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Event/EventContainers/EventContainers/IdentifiableValueContainer.h
+20
-15
20 additions, 15 deletions
...ntContainers/EventContainers/IdentifiableValueContainer.h
with
20 additions
and
15 deletions
Event/EventContainers/EventContainers/IdentifiableValueContainer.h
+
20
−
15
View file @
2a5819fb
...
...
@@ -6,7 +6,7 @@
#define EVENTCONTAINERS_IDENTIFIABLEVALUECONTAINER_H
#include
"EventContainers/IdentifiableValueCache.h"
#include
<set>
class
IdentifiableValueContainerBase
{};
...
...
@@ -30,14 +30,14 @@ public:
///Self Owning Constructor
///Pass the maximum hash to size the cache and the defaultValue which will be interpreted as an empty value
IdentifiableValueContainer
(
size_t
maxSize
,
T
defaultValue
)
:
m_mask
(
maxSize
,
false
),
m_own
(
true
)
IdentifiableValueContainer
(
size_t
maxSize
,
T
defaultValue
)
:
m_own
(
true
)
{
m_cache
=
new
IdentifiableValueCache
<
T
>
(
maxSize
,
std
::
move
(
defaultValue
));
}
///External Cache Constructor
///Pass the external cache to set up a view specific view interface
IdentifiableValueContainer
(
IdentifiableValueCache
<
T
>
*
ptr
)
:
m_mask
(
ptr
->
maxSize
()),
IdentifiableValueContainer
(
IdentifiableValueCache
<
T
>
*
ptr
)
:
m_cache
(
ptr
),
m_own
(
false
)
{}
...
...
@@ -53,7 +53,7 @@ public:
bool
setOrDrop
(
size_t
i
,
const
T
&
value
);
///Return the maxSize of the collection
size_t
maxSize
()
const
{
return
m_
mask
.
s
ize
();
}
size_t
maxSize
()
const
{
return
m_
cache
->
maxS
ize
();
}
///Return the number of entries set and accessible according to the mask.
///This is not a trivial function do not repeatedly call.
...
...
@@ -74,8 +74,9 @@ public:
/// Obtain const access to the cache
const
Cache
*
cache
()
const
{
return
m_cache
;
}
const
std
::
set
<
size_t
>&
getMask
()
const
{
return
m_mask
;
}
private
:
std
::
vector
<
bool
>
m_mask
;
std
::
set
<
size_t
>
m_mask
;
Cache
*
m_cache
;
bool
m_own
;
};
...
...
@@ -83,44 +84,48 @@ private:
template
<
class
T
>
bool
IdentifiableValueContainer
<
T
>::
present
(
size_t
i
)
const
{
return
m_mask
.
a
t
(
i
);
return
m_mask
.
coun
t
(
i
);
}
template
<
class
T
>
std
::
vector
<
std
::
pair
<
size_t
,
T
>>
IdentifiableValueContainer
<
T
>::
getAll
()
const
{
std
::
vector
<
std
::
pair
<
size_t
,
T
>>
list
;
list
.
reserve
(
m_mask
.
size
());
const
auto
&
raw
=
m_cache
->
rawReadAccess
();
for
(
size_t
i
=
0
;
i
<
m_mask
.
size
();
i
++
){
if
(
m_mask
[
i
])
list
.
emplace_back
(
i
,
raw
[
i
].
load
());
for
(
size_t
i
:
m_mask
){
list
.
emplace_back
(
i
,
raw
[
i
].
load
());
}
return
list
;
}
template
<
class
T
>
T
IdentifiableValueContainer
<
T
>::
retrieve
(
size_t
i
)
const
{
if
(
m_mask
[
i
])
return
m_cache
->
retrieve
(
i
);
auto
r
=
m_cache
->
retrieve
(
i
);
//Should be quicker to establish empty cache than empty mask with a std::set
//So the cache is checked first
if
(
r
!=
m_cache
->
emptyValue
()
&&
present
(
i
))
return
r
;
else
return
m_cache
->
emptyValue
();
}
template
<
class
T
>
bool
IdentifiableValueContainer
<
T
>::
tryAddFromCache
(
size_t
i
){
if
(
i
>=
m
_mask
.
s
ize
())
return
false
;
if
(
i
>=
m
axS
ize
())
return
false
;
bool
b
=
m_cache
->
present
(
i
);
m_mask
[
i
]
=
b
;
if
(
b
)
m_mask
.
emplace
(
i
)
;
return
b
;
}
template
<
class
T
>
size_t
IdentifiableValueContainer
<
T
>::
numberSet
()
const
{
size_t
count
=
0
;
for
(
bool
b
:
m_mask
)
count
+=
b
;
return
count
;
return
m_mask
.
size
();
}
template
<
class
T
>
bool
IdentifiableValueContainer
<
T
>::
setOrDrop
(
size_t
i
,
const
T
&
value
){
bool
b
=
m_cache
->
setOrDrop
(
i
,
value
);
m_mask
[
i
]
=
true
;
m_mask
.
emplace
(
i
)
;
return
b
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment