Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 76e0998

Browse files
committed
Change LockFreeArray::FindValid from O(n) to O(1).
1 parent a8b1b0c commit 76e0998

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

src/common/container/lock_free_array.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,18 @@ ValueType LOCK_FREE_ARRAY_TYPE::FindValid(
7373
const std::size_t &offset, const ValueType &invalid_value) const {
7474
LOG_TRACE("Find Valid at %lu", offset);
7575

76-
std::size_t valid_array_itr = 0;
77-
std::size_t array_itr;
78-
auto lock_free_array_offset = lock_free_array.size();
79-
for (array_itr = 0; array_itr < lock_free_array_offset; array_itr++) {
80-
auto value = lock_free_array.at(array_itr);
81-
if (value != invalid_value) {
82-
// Check offset
83-
if (valid_array_itr == offset) {
84-
return value;
85-
}
86-
87-
// Update valid value count
88-
valid_array_itr++;
89-
}
76+
ValueType value = invalid_value;
77+
if ((lock_free_array.size() > offset)) {
78+
value = lock_free_array.at(offset);
79+
} else {
80+
return invalid_value;
81+
}
82+
83+
if (value != invalid_value)
84+
return value;
85+
else {
86+
return invalid_value;
9087
}
91-
92-
return invalid_value;
9388
}
9489

9590
template <typename ValueType>

src/concurrency/transaction_context.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ RWType TransactionContext::GetRWType(const ItemPointer &location) {
9595
void TransactionContext::RecordRead(const ItemPointer &location) {
9696
PELOTON_ASSERT(rw_set_.count(location) == 0 ||
9797
(rw_set_[location] != RWType::DELETE && rw_set_[location] != RWType::INS_DEL));
98-
99-
if (rw_set_.count(location) == 0) {
100-
rw_set_[location] = RWType::READ;
98+
auto rw_set_it = rw_set_.find(location);
99+
if (rw_set_it != rw_set_.end()) {
100+
return;
101101
}
102+
rw_set_[location] = RWType::READ;
102103
}
103104

104105
void TransactionContext::RecordReadOwn(const ItemPointer &location) {

src/storage/data_table.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ std::shared_ptr<storage::TileGroup> DataTable::GetTileGroup(
10021002
PELOTON_ASSERT(tile_group_offset < GetTileGroupCount());
10031003

10041004
auto tile_group_id =
1005-
tile_groups_.Find(tile_group_offset);
1005+
tile_groups_.FindValid(tile_group_offset, invalid_tile_group_id);
10061006

10071007
return GetTileGroupById(tile_group_id);
10081008
}

0 commit comments

Comments
 (0)