Skip to content

Commit

Permalink
#3: Add doxygen and key checking when detaching from set
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrepebay committed Apr 28, 2023
1 parent bc9aa38 commit bd77f0c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
15 changes: 7 additions & 8 deletions block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@ Block::Block(uint64_t b_id,
{}

uint64_t Block::detach_object_id(uint64_t o_id) {
try {
if(auto search = this->attached_object_ids.find(o_id);
search != this->attached_object_ids.end()) {
this->attached_object_ids.erase(o_id);
}
catch(const nb::type_error e) {
std::cerr << e.what() << '\n';
else {
throw nb::type_error(
"object id " + std::to_string(o_id) +
" is not attached to block " + std::to_string(this->get_id())
);
}
return this->attached_object_ids.size();
}

void Block::attach_object_id(uint64_t o_id) {
this->attached_object_ids.insert(o_id);
}


std::string Block::to_string() const {
std::string out;
out += "Block id: " + std::to_string(this->get_id())
Expand Down
28 changes: 25 additions & 3 deletions block.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <iostream>
#include <list>
#include <map>
#include <format>
#include <unordered_set>

namespace nb = nanobind;
Expand All @@ -29,14 +28,37 @@ struct Block
uint64_t home_id;
double size = 0;
std::unordered_set<uint64_t> attached_object_ids;

/**
* Return block object ids.
*/
std::unordered_set<uint64_t> get_attached_object_ids() const { return this->attached_object_ids; };
public:
/**
* Return block ID.
*/
uint64_t get_id() const { return this->index; };

/**
* Return block home ID.
*/
uint64_t get_home_id() const { return this->home_id; };

/**
* Return block size.
*/
double get_size() const { return this->size; };
std::unordered_set<uint64_t> get_attached_object_ids() const { return this->attached_object_ids; };


/**
* Try to detach object ID from block and return length.
*/
uint64_t detach_object_id(uint64_t);
void attach_object_id(uint64_t);

/**
* Attach object ID to block.
*/
void attach_object_id(uint64_t o_id) { this->attached_object_ids.insert(o_id); };

std::string to_string() const;

Expand Down

0 comments on commit bd77f0c

Please sign in to comment.