Recycler

Used for disposing and claiming segments from the blockfile. Therefore responsible for keeping track of unused segments. and making sure these are used so the file does not continue. growing.

Members

Functions

claim
const(Index) claim(ulong segment_size)

Claims a free segment. Priority is first to use segments already in the disposed list from to_be_recycled. Next is to use a element in the recycler indices. Therefore removing a segment from the recycler. Secondly if no available segments then it appends a new segment to the blockfile and changes the owners last block index.

dispose
void dispose(const(Index) index, ulong segment_size)

Disposes a used segment. This means adding a NEW segment to the recycler.

dump
void dump(File fout)

Dumps the segments in the recycler.

dumpToBeRecycled
void dumpToBeRecycled(File fout)

Dumps the segments in the to_be_recycled array.

insert
void insert(RecycleSegment* segment)

Insert a single segment into the recycler.

insert
void insert(R segment_range)

Inserts a range of segments into the recycler.

read
void read(Index index)

Reads an element from the blockfile.

recycle
void recycle(RecycleSegment*[] recycle_segments)

Recycles the segments. Goes over the list of recycle_segments. First it takes the lowerbound. If there is a element in the lowerbound, the index of the current segment is changed to the one of the lowerbound.back and the lower_range.back is removed. The same step is used for the upperbound using the front of the elements. We go over all the new segments that needs to be recycled. First we get lowerBound in the indices. The indices are sorted by index meaning we get all sgements by indices as a range that are smaller or equal to our segment. If the segments connext we add remove it and create a new one. The same procedure is used for the upperrange.

remove
void remove(RecycleSegment* segment)

Removes a segment from the recycler.

sortedRecycleSegments
auto sortedRecycleSegments()

Function to sort the segments by their size. It returns a assumeSorted of the segments.

write
Index write()

Writes the data to the file. First it calls recycler with the to_be_recycled. Afterwards it goes through and updates the pointer chain.

Variables

indices
Indices indices;

Indices that are stored in the blockfile.

owner
BlockFile owner;

* Checks if the indices and segments are the same length; *//// The blockfile owne

segments
RecycleSegment*[] segments;

The other way to sort. Sorted by segment size therefore allowing overlaps.

to_be_recycled
RecycleSegment*[] to_be_recycled;

RecycleSegments that are disposed and need to be added to the recycler.