HashDBM constructor

HashDBM(
  1. RandomAccessFile file, {
  2. int buckets = 10007,
  3. bool flush = true,
  4. bool crc = false,
})

Open a new database. Optional parameters are: buckets which sets the number of hash buckets to use, flush which when set to true will force data to disk every time it is changed, and crc which will enable CRC checks on underlying records if set to true. The defaults are generally good enough.

Implementation

HashDBM(RandomAccessFile file,
    {int buckets = 10007, bool flush = true, bool crc = false})
    : _file = file,
      _flush = flush,
      _header = HashHeader(buckets) {
  final length = file.lengthSync();
  if (length > _header.length) {
    _header.read(_file);
  }
  if (_header.magic != HashHeader.MAGIC) {
    throw DBMException(500, 'HashHeader magic mismatch: ${_header.magic}');
  }

  // Update with current time
  _header.modified = DateTime.now().millisecondsSinceEpoch;
  _header.write(_file);

  // Create the memory pool
  _memoryPool = MemoryPool(_file, _header.memPoolOffset);

  // Create the record pool
  _recordPool = HashRecordPool(
      _file, _memoryPool.end + 1, _memoryPool, _header.numBuckets,
      crc: crc);
}