Skip to content

Replace several bool values in ProbabilityState with a single uint8_t status to save space. #44

Open
@ifndefJOSH

Description

@ifndefJOSH

Currently there are a bunch of boolean values in the ProbabilityState class which could be condensed into something smaller:

class ProbabilityState {
public:
...
	bool assignedInRemapping;
	bool isNew;
	bool wasPutInTerminalQueue;
	bool preTerminated;
	bool deadlock;
...
// More code here
}

We could use a single uint8_t status to hold all of these values, with bit 0 being assignedInRemapping, bit 1 being isNew, etc... and use bitwise math to get the values like so:

// Somewhere Above
const uint8_t ASSIGNED_IN_REMAPPING_INDEX = 0;
const uint8_t IS_NEW_INDEX = 1;
...
void 
ProbabilityState::setAssignedInRemapping(bool value) {
    // Create bitmask and zero out the desired bit
    status &= ~(0x1 << ASSIGNED_IN_REMAPPING_INDEX);
    // Set the desired bit to the desired value
    status |= (uint8_t) value << ASSIGNED_IN_REMAPPING_INDEX;
}
bool
ProbabilityState::wasAssignedInRemapping() {
    return (status >> ASSIGNED_IN_REMAPPING_INDEX) & 0x1;
}

If anyone wants to help out on this, I think this would be a good first issue for a newcomer.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions