Skip to content

core: Add "add" operation for the derived set #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Allocations/Set.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ class Set {
*to++ = *from++;
}
}
void Add(const Set<Offset> &other) {
uint64_t *to = _asU64.get();
const uint64_t *from = other._asU64.get();
for (AllocationIndex i = 0; i < _numU64; i++) {
*to++ |= *from++;
}
}
void Subtract(const Set<Offset> &other) {
uint64_t *to = _asU64.get();
const uint64_t *from = other._asU64.get();
Expand Down
28 changes: 20 additions & 8 deletions src/Allocations/Subcommands/Subcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Subcommand : public Commands::Subcommand {
public:
typedef typename Directory<Offset>::AllocationIndex AllocationIndex;
typedef typename Directory<Offset>::Allocation Allocation;
enum SetOperationType { ASSIGN, ADD, SUBTRACT };
Subcommand(const ProcessImage<Offset>& processImage,
typename Visitor::Factory& visitorFactory,
typename Iterator::Factory& iteratorFactory,
Expand Down Expand Up @@ -181,8 +182,7 @@ class Subcommand : public Commands::Subcommand {
}
}

bool assignDefault = false;
bool subtractFromDefault = false;
SetOperationType setOperationType;

size_t numSetOperationArguments = context.GetNumArguments("setOperation");
if (numSetOperationArguments > 0) {
Expand All @@ -192,9 +192,11 @@ class Subcommand : public Commands::Subcommand {
}
const std::string& operation = context.Argument("setOperation", 0);
if (operation == "assign") {
assignDefault = true;
setOperationType = SetOperationType::ASSIGN;
} else if (operation == "add") {
setOperationType = SetOperationType::ADD;
} else if (operation == "subtract") {
subtractFromDefault = true;
setOperationType = SetOperationType::SUBTRACT;
} else {
std::cerr << "Set operation " << operation << " is not supported.\n";
switchError = true;
Expand Down Expand Up @@ -345,10 +347,16 @@ class Subcommand : public Commands::Subcommand {

extendedVisitor.Visit(index, *allocation, visitorRef);
}
if (assignDefault) {
_setCache.GetDerived().Assign(visited);
} else if (subtractFromDefault) {
_setCache.GetDerived().Subtract(visited);
switch (setOperationType) {
case SetOperationType::ASSIGN:
_setCache.GetDerived().Assign(visited);
break;
case SetOperationType::ADD:
_setCache.GetDerived().Add(visited);
break;
case SetOperationType::SUBTRACT:
_setCache.GetDerived().Subtract(visited);
break;
}
}

Expand Down Expand Up @@ -386,6 +394,10 @@ class Subcommand : public Commands::Subcommand {
" be used for automated bug detection.\n\n"
"/geometricSample <base-in-decimal> causes only entries 1, b, "
"b**2, b**3...\n to be visited.\n\n"
"use \"/setOperation <operation>\" to derive a custome set.\n"
" assign: initialize the derived set based on some calculated set.\n"
" add: add some calculated set to the derived set.\n"
" subtrace: subtract some calculated set from the derived set.\n\n"
"After restrictions have been applied, the /extend switch can be"
" used to extend\n"
" the set to adjacent allocations. See USERGUIDE.md for details.\n";
Expand Down