/*
* Copyright 2012 Steven Gribble
*
* This file is part of the UW CSE 333 course project sequence
* (333proj).
*
* 333proj is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 333proj is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 333proj. If not, see .
*/
#ifndef HW3_HASHTABLEREADER_H_
#define HW3_HASHTABLEREADER_H_
#include // for (FILE*).
#include // for std::list.
#include "./LayoutStructs.h"
using std::list;
namespace hw3 {
// A HashTableReader is the base class for the different kinds of hash table
// readers. Its derived classes are the DocTableReader, the IndexTableReader,
// and the DocPositionsReader.
class HashTableReader {
public:
// Construct a HashTableReader reader.
//
// Arguments:
// - f: an open (FILE*) for the index file to read. Takes ownership of
// the passed-in file's memory, and will also fclose() it on destruction.
// - offset: the hash table's byte offset within the file.
HashTableReader(FILE* f, IndexFileOffset_t offset);
virtual ~HashTableReader();
protected:
// Given a 64-bit hash key, this function navigates through
// the on-disk hash table and returns a list of file offsets of
// "element" fields within the bucket that the hash key maps to.
// Only subclasses may invoke this.
//
// Arguments:
// - hash_val: the 64-bit hash key to look up.
//
// Returns:
// - A list of offsets of "element" fields inside the bucket that
// the hash value maps to. If no elements are in the bucket,
// this returns an empty list.
list LookupElementPositions(HTKey_t hash_val) const;
// The open (FILE*) stream associated with this hash table.
FILE* file_;
// The byte offset within the file that this hash table starts at.
IndexFileOffset_t offset_;
// A cached copy of the total number of buckets in this hash table.
BucketListHeader header_;
private:
// This friend declaration is here so that the Test_HashTableReader
// unit test fixture can access protected member variables of
// HashTableReader. See test_hashtablereader.h for details.
friend class Test_HashTableReader;
DISALLOW_COPY_AND_ASSIGN(HashTableReader);
};
} // namespace hw3
#endif // HW3_HASHTABLEREADER_H_