forked from defuse/crackstation-hashdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsortidx.h
42 lines (33 loc) · 1.13 KB
/
sortidx.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef CRACKSTATION_SORTIDX_H
#define CRACKSTATION_SORTIDX_H
// Includes
#include <atomic>
#include <iostream>
#include <limits>
#include <string>
#include "filearray.h"
#include "progressbar.h"
// Functions
// Returns the parent index.
constexpr size_t getParent( size_t i ) {
return (i - 1) / 2;
}
// Returns the left child index.
constexpr size_t getLeft( size_t i ) {
return i * 2 + 1;
}
// Returns the right child index.
constexpr size_t getRight( size_t i ) {
return i * 2 + 2;
}
// Sorts an idx file. Using chachSize bytes of RAM to speed it up.
void sortIDX( const std::string & idxFile, size_t cacheByteSize, bool quiet );
// Turns the idx file into a heap (first step of heapsort)
void heapifyIDX( FileArray & fileArray, ProgressBar & progressBar, size_t heapifyLimit );
// Sorts the idx heap (second step of heapsort)
void sortIDXHeap( FileArray & fileArray, ProgressBar & progressBar, size_t numDataSets );
// Checks whether a index is in the heap
bool isInHeap( size_t pos );
// Moves a element down the heap until it is at the right position
void orderHeap( FileArray & fileArray, FileArray::IndexEntry &top, size_t posTop );
#endif