HOG2
DiskBitFile.h
Go to the documentation of this file.
1 //
2 // DiskBitFile.h
3 // Rubik
4 //
5 // Created by Nathan Sturtevant on 4/5/13.
6 // Copyright (c) 2013 Nathan Sturtevant. All rights reserved.
7 //
8 
9 #ifndef __Rubik__DiskBitFile__
10 #define __Rubik__DiskBitFile__
11 
12 #include "EnvUtil.h"
13 #include <iostream>
14 #include <cassert>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <stdint.h>
18 #include <string.h>
19 
20 //const int BITS = 4;
21 #define BITS 4
22 
24 {
25 public:
26  DiskBitFile(const char *pre);
27  ~DiskBitFile();
28  void Init(const std::vector<bucketData> &buckets);
29 
30  // incoming offset is in entries, not bytes
31  void WriteFileDepth(int bucket, int64_t offset, uint8_t value);
32  int ReadFileDepth(int bucket, int64_t offset);
33  void CloseReadWriteFile();
34 
35  uint8_t *ReadChunk(int bucket, int64_t offset, int numEntries, uint8_t *data);
36  void CloseReadFile();
37 
38  uint64_t GetBytesRead() const { return bytesRead; }
39  uint64_t GetBytesWritten() const { return bytesWritten; }
40 private:
41  void FlushCache();
42  const char *getBucketFileName(int bucket, int subBucket);
43 
44  // data for reading and writing depths
45  FILE *outputFile;
48  int64_t cacheOffset; // beginning of cache [in bytes]
49 
50  // data for reading chunks
51  bool fileOpen;
52  FILE *chunkFile;
53  int64_t fileOffset;
54  int64_t currBucket;
55  int64_t currSubBucket;
56 
57  const static int subBucketBits = 30;
58  const static int64_t cacheSize = 1ull<<22;//4096;//1024*512; // no problem(?) // 4 MB!
59  int64_t theCacheSize; // valid bytes in the cache
60  int64_t cacheFilePosition; // current offset in file (bytes)
62  uint8_t cache[cacheSize];
63 
65  char bucketFileName[255];
66  char prefix[64];
67 };
68 
69 
70 
71 #endif
DiskBitFile::getBucketFileName
const char * getBucketFileName(int bucket, int subBucket)
Definition: DiskBitFile.cpp:311
DiskBitFile::cache
uint8_t cache[cacheSize]
Definition: DiskBitFile.h:62
DiskBitFile::currSubBucket
int64_t currSubBucket
Definition: DiskBitFile.h:55
DiskBitFile::outputSubBucket
int outputSubBucket
Definition: DiskBitFile.h:47
DiskBitFile::chunkFile
FILE * chunkFile
Definition: DiskBitFile.h:52
DiskBitFile::bytesRead
uint64_t bytesRead
Definition: DiskBitFile.h:64
DiskBitFile::cacheFilePosition
int64_t cacheFilePosition
Definition: DiskBitFile.h:60
DiskBitFile::CloseReadWriteFile
void CloseReadWriteFile()
Definition: DiskBitFile.cpp:41
DiskBitFile::CloseReadFile
void CloseReadFile()
Definition: DiskBitFile.cpp:197
DiskBitFile::WriteFileDepth
void WriteFileDepth(int bucket, int64_t offset, uint8_t value)
Definition: DiskBitFile.cpp:56
DiskBitFile::GetBytesWritten
uint64_t GetBytesWritten() const
Definition: DiskBitFile.h:39
DiskBitFile::ReadFileDepth
int ReadFileDepth(int bucket, int64_t offset)
Definition: DiskBitFile.cpp:115
DiskBitFile::~DiskBitFile
~DiskBitFile()
Definition: DiskBitFile.cpp:35
DiskBitFile::fileOffset
int64_t fileOffset
Definition: DiskBitFile.h:53
DiskBitFile::bytesWritten
uint64_t bytesWritten
Definition: DiskBitFile.h:64
DiskBitFile::FlushCache
void FlushCache()
Definition: DiskBitFile.cpp:260
DiskBitFile::cacheChanged
bool cacheChanged
Definition: DiskBitFile.h:61
DiskBitFile::DiskBitFile
DiskBitFile(const char *pre)
Definition: DiskBitFile.cpp:11
DiskBitFile::Init
void Init(const std::vector< bucketData > &buckets)
Definition: DiskBitFile.cpp:275
DiskBitFile::fileOpen
bool fileOpen
Definition: DiskBitFile.h:51
DiskBitFile::bucketFileName
char bucketFileName[255]
Definition: DiskBitFile.h:65
DiskBitFile::outputBucket
int outputBucket
Definition: DiskBitFile.h:46
EnvUtil.h
DiskBitFile::theCacheSize
int64_t theCacheSize
Definition: DiskBitFile.h:59
DiskBitFile::GetBytesRead
uint64_t GetBytesRead() const
Definition: DiskBitFile.h:38
DiskBitFile::ReadChunk
uint8_t * ReadChunk(int bucket, int64_t offset, int numEntries, uint8_t *data)
Definition: DiskBitFile.cpp:208
DiskBitFile::outputFile
FILE * outputFile
Definition: DiskBitFile.h:45
DiskBitFile::subBucketBits
const static int subBucketBits
Definition: DiskBitFile.h:57
DiskBitFile::cacheSize
const static int64_t cacheSize
Definition: DiskBitFile.h:58
DiskBitFile::prefix
char prefix[64]
Definition: DiskBitFile.h:66
DiskBitFile
Definition: DiskBitFile.h:23
DiskBitFile::cacheOffset
int64_t cacheOffset
Definition: DiskBitFile.h:48
DiskBitFile::currBucket
int64_t currBucket
Definition: DiskBitFile.h:54