Skip to content

Commit

Permalink
RmDom: better isRemovedEv_
Browse files Browse the repository at this point in the history
  • Loading branch information
fchn289 committed Nov 22, 2023
1 parent 6cbc3da commit 2e77f71
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/domino/RmEvDom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// ***********************************************************************************************
#pragma once

#include <unordered_set>

using namespace std;

namespace RLib
Expand All @@ -31,12 +33,15 @@ class RmEvDom : public aDominoType
explicit RmEvDom(const UniLogName& aUniLogName) : aDominoType(aUniLogName) {}

bool rmEvOK(const Domino::Event) override;
bool isRemoved(const Domino::Event aEv) const { return aEv < isRemovedEv_.size() ? isRemovedEv_[aEv] : false; }
bool isRemoved(const Domino::Event aEv) const { return isRemovedEv_.count(aEv); }
Domino::Event recycleEv() override;

// -------------------------------------------------------------------------------------------
private:
vector<bool> isRemovedEv_; // bitmap & dyn expand, [event]=true(rm-ed) or not
// -------------------------------------------------------------------------------------------
// - REQ: min mem
// - REQ: fast (eg isRemoved(), insert, del)
// - req: better FIFO
unordered_set<Domino::Event> isRemovedEv_;

public:
using aDominoType::oneLog;
Expand All @@ -46,13 +51,12 @@ class RmEvDom : public aDominoType
template<typename aDominoType>
Domino::Event RmEvDom<aDominoType>::recycleEv()
{
for (Domino::Event ev = 0; ev < isRemovedEv_.size(); ev++)
if (isRemovedEv_[ev])
{
isRemovedEv_[ev] = false;
return ev;
}
return Domino::D_EVENT_FAILED_RET;
if (isRemovedEv_.empty())
return Domino::D_EVENT_FAILED_RET;

const auto ev = *(isRemovedEv_.begin());
isRemovedEv_.erase(isRemovedEv_.begin());
return ev;
}

// ***********************************************************************************************
Expand All @@ -66,9 +70,7 @@ bool RmEvDom<aDominoType>::rmEvOK(const Domino::Event aEv)
return false;

// rmEvOK() succ; must NOT rely on aDominoType at all since info of aEv is removed
if (aEv >= isRemovedEv_.size())
isRemovedEv_.resize(aEv + 1);
isRemovedEv_[aEv] = true;
isRemovedEv_.insert(aEv);
return true;
}

Expand All @@ -77,4 +79,5 @@ bool RmEvDom<aDominoType>::rmEvOK(const Domino::Event aEv)
// YYYY-MM-DD Who v)Modification Description
// .......... ......... .......................................................................
// 2023-11-14 CSZ 1)create
// 2023-11-22 CSZ - better isRemovedEv_
// ***********************************************************************************************

0 comments on commit 2e77f71

Please sign in to comment.