Skip to content

Commit

Permalink
return vector, not set
Browse files Browse the repository at this point in the history
set seems a bit like overkill - we already know the items are unique,
and the consumer is likely just going to iterate over them
  • Loading branch information
cldellow committed Nov 17, 2023
1 parent 2f61bc9 commit 3e6df15
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/attribute_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ struct AttributeStore {
int lookups=0;

AttributeIndex add(AttributeSet &attributes);
std::set<AttributePair, AttributePairStore::key_value_less> get(AttributeIndex index) const;
std::vector<AttributePair> get(AttributeIndex index) const;
void reportSize() const;
void doneReading();

Expand Down
8 changes: 3 additions & 5 deletions src/attribute_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,7 @@ AttributeIndex AttributeStore::add(AttributeSet &attributes) {
return rv;
}

// TODO: consider implementing this as an iterator, or returning a cheaper
// container than a set (vector?)
std::set<AttributePair, AttributePairStore::key_value_less> AttributeStore::get(AttributeIndex index) const {
std::vector<AttributePair> AttributeStore::get(AttributeIndex index) const {
try {
uint32_t shard = index >> (32 - SHARD_BITS);
uint32_t offset = index & (~(~0u << (32 - SHARD_BITS)));
Expand All @@ -220,9 +218,9 @@ std::set<AttributePair, AttributePairStore::key_value_less> AttributeStore::get(

const size_t n = attrSet.numPairs();

std::set<AttributePair, AttributePairStore::key_value_less> rv;
std::vector<AttributePair> rv;
for (size_t i = 0; i < n; i++) {
rv.insert(pairStore.getPair(attrSet.getPair(i)));
rv.push_back(pairStore.getPair(attrSet.getPair(i)));
}

return rv;
Expand Down

0 comments on commit 3e6df15

Please sign in to comment.