Skip to content
Snippets Groups Projects
Commit ccac078b authored by Mahyar Vahabi's avatar Mahyar Vahabi
Browse files

changed eviction

parent 813194b5
No related branches found
No related tags found
No related merge requests found
Pipeline #617379 failed
......@@ -9,6 +9,7 @@
#include <vector>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <random>
#include <cstdlib>
......@@ -17,7 +18,7 @@ using namespace std;
// ORAM parameters (for demonstration)
const int TREE_HEIGHT = 3; // Height of the tree (number of levels - 1)
const int BUCKET_CAPACITY = 4; // Maximum number of blocks per bucket
const int BUCKET_CAPACITY = 3; // Maximum number of blocks per bucket
const int NUM_LEAVES = 1 << TREE_HEIGHT; // 2^TREE_HEIGHT leaves
const int NUM_BUCKETS = (1 << (TREE_HEIGHT + 1)) - 1; // Total number of buckets in a complete binary tree
const string STATE_FILE = "oram_state.db"; // File to persist ORAM state
......@@ -148,25 +149,26 @@ void saveState() {
outfile.close();
}
// Eviction: Write blocks from the stash back into the tree along the given path.
// For each bucket on the path, try to place blocks from the stash that "belong" to that bucket.
void evictPath(const vector<int>& path) {
void evictPath(vector<int> path) {
reverse(path.begin(), path.end()); // Evict from leaf to root
for (int bucketIdx : path) {
int capacity = BUCKET_CAPACITY - tree[bucketIdx].size();
if (capacity <= 0) continue;
// Iterate over stash and try to place blocks whose assigned leaf's path includes this bucket.
for (auto it = stash.begin(); it != stash.end(); ) {
int assignedLeaf = posMap[it->id]; // Each block’s current assigned leaf.
vector<int> toRemove;
for (auto it = stash.begin(); it != stash.end(); ++it) {
int assignedLeaf = posMap[it->id];
vector<int> blockPath = getPathIndices(assignedLeaf);
if (find(blockPath.begin(), blockPath.end(), bucketIdx) != blockPath.end()) {
tree[bucketIdx].push_back(*it);
it = stash.erase(it);
capacity--;
if (capacity == 0) break;
} else {
++it;
toRemove.push_back(it->id);
if (--capacity == 0) break;
}
}
for (int id : toRemove) {
stash.erase(remove_if(stash.begin(), stash.end(), [&](Block b) { return b.id == id; }), stash.end());
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment