/usr/include/kmer/util/bigQueue.H is in libkmer-dev 0~20150903+r2013-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | #ifndef BIGQUEUE_H
#define BIGQUEUE_H
#include "util++.H"
// A disk-backed list of user-defined objects.
//
// At creation time, you can opt to have it sorted, using a
// user-defined function.
// An list based on a variable length object (let alone a sort!)
// must use some form of dereferencing scheme. So, if you want to
// use variable length records, you have to use pointers, and supply
// functions to do everything (compare, read, write).
//
// On the otherhand, it would be quite more convenient (to use) if we
// used objects (would need copy, compare, read, write).
//
// 1) Restrict to void*, fixed block size, functions for compare,
// destroy. read, write and copy done with fread(), fwrite() and
// memcpy().
//
// 2) Restrict to void*, functions for compare, read, write and
// destroy. I allocate an array of pointers. Assume shallow copies
// are ok (qsort will be used). On construct, we need to know the
// size of the data so we know how many objects to buffer before
// sorting and writing. It's also possible to use fread() and
// fwrite().
//
// 3) Restrict to objects, operators for copy, compare, read, write,
// default construct, destroy. I allocate an array of objects.
//
// 1 is the easiest to write, 2 and 3 are conceptually the same. 1
// cannot write out deep data (pointer to string). 2 is a trivial
// extenstion to 1, and fixes that. 3 is the correct version, but I
// don't want to deal with streams io. So, 2 it is.
//
class bigQueue {
public:
// Initialize the bigQueue for anonymous storage, with an
// option to later save the array.
//
bigQueue(bool (*readfcn)(FILE *, void *),
bool (*writfcn)(FILE *, void *),
void (*killfcn)(void *),
uint32 objectSize,
char *tmpPath) {
_initialize(0L, readfcn, writfcn, killfcn, objectSize, 0, tmpPath, 0L);
};
// Initialize the bigQueue with a file of objects, presumabely from
// a previous invocation of bigQueue.
//
bigQueue(bool (*readfcn)(FILE *, void *),
bool (*writfcn)(FILE *, void *),
void (*killfcn)(void *),
uint32 objectSize,
char *tmpPath,
char *filename) {
_initialize(0L, readfcn, writfcn, killfcn, objectSize, 0, tmpPath, filename);
};
// Initialize the bigQueue for sorting.
//
bigQueue(int (*sortfcn)(const void *a, const void *b),
bool (*readfcn)(FILE *, void *),
bool (*writfcn)(FILE *, void *),
void (*killfcn)(void *),
uint32 objectSize,
uint32 memoryToUse,
char *tmpPath) {
_initialize(sortfcn, readfcn, writfcn, killfcn, objectSize, memoryToUse, tmpPath, 0L);
};
private:
void _initialize(int (*sortfcn)(const void *a, const void *b),
bool (*readfcn)(FILE *f, void *a),
bool (*writfcn)(FILE *f, void *a),
void (*killfcn)(void *),
uint32 objectSize,
uint32 memoryToUse,
char *tmppath,
char *filename);
public:
~bigQueue();
// Add elements to the end of the array.
void add(void *);
// We are designed for streaming access.
bool next(void);
void *get(void);
// Rewind to the start. Sortable must be sorted.
void rewind(void);
// Save the anonymous array into a real file.
void save(char *filepath);
// Sort the sortable. Flush the flushable.
void sort(void);
void flush(void);
private:
void sortAndWriteBuffer(void);
void clearBuffer(void);
void mergeTemporaryFiles(void);
char *_saveFile;
char *_tmpPath;
int (*_sortFunction)(const void *a, const void *b);
bool (*_writFunction)(FILE *f, void *a);
bool (*_readFunction)(FILE *f, void *a);
void (*_killFunction)(void *a);
uint32 _objectSize;
uint32 _memoryToUse;
uint32 _maxOpenFiles;
uint32 _numTemporaryFiles;
uint32 _numMergeFiles;
// _temporaryFiles is all the opened output files. If we aren't
// sorting, then only the first one is opened.
//
// _inputFile is a dup of the first temporary file. If we are
// sorting, and you start reading before you sort, then you'll get
// a very short read.
//
FILE **_temporaryFiles;
FILE *_inputFile;
// Stores things read back from disk, for return to the user.
// Currently just one, but should be extended to many.
//
void *_thingBuffer;
uint32 _bufferMax;
uint32 _bufferLen;
void **_buffer;
};
#endif // BIGQUEUE_H
|