2020-09-17 23:02:40 +03:00
|
|
|
// Copyright (c) Vitaliy Filippov, 2019+
|
2021-02-06 01:26:07 +03:00
|
|
|
// License: VNPL-1.1 (see README.md for details)
|
2020-09-17 23:02:40 +03:00
|
|
|
|
2019-10-28 01:22:01 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
// Hierarchical bitmap allocator
|
2019-11-27 00:50:57 +03:00
|
|
|
class allocator
|
2019-10-28 01:22:01 +03:00
|
|
|
{
|
2021-03-13 02:00:22 +03:00
|
|
|
uint64_t total;
|
2019-10-28 01:22:01 +03:00
|
|
|
uint64_t size;
|
2019-11-28 20:23:26 +03:00
|
|
|
uint64_t free;
|
2019-10-28 01:22:01 +03:00
|
|
|
uint64_t last_one_mask;
|
2019-11-27 00:50:57 +03:00
|
|
|
uint64_t *mask;
|
|
|
|
public:
|
|
|
|
allocator(uint64_t blocks);
|
|
|
|
~allocator();
|
2021-03-28 00:16:12 +03:00
|
|
|
bool get(uint64_t addr);
|
2019-11-27 00:50:57 +03:00
|
|
|
void set(uint64_t addr, bool value);
|
|
|
|
uint64_t find_free();
|
2019-11-28 20:23:26 +03:00
|
|
|
uint64_t get_free_count();
|
2019-10-28 01:22:01 +03:00
|
|
|
};
|
2021-01-03 20:23:54 +03:00
|
|
|
|
|
|
|
void bitmap_set(void *bitmap, uint64_t start, uint64_t len, uint64_t bitmap_granularity);
|