SwatDB
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
HashIndexScanner Class Reference

#include <hashindexscanner.h>

Collaboration diagram for HashIndexScanner:
Collaboration graph
[legend]

Public Member Functions

 HashIndexScanner (HashIndexFile *index)
 Constructor for scanning all entries of the Index.
 
 HashIndexScanner (HashIndexFile *index, Key *key_val)
 Constructor for equality scan, this scan is over all K* entries with a matching key value to the passed key_val.
 
 ~HashIndexScanner ()
 Destructor.
 
RecordId getNext ()
 Returns RecordId of the next matching K* in the scan.
 
RecordId getNext (Key *key)
 Returns RecordId of the next matching K* and sets the data part of the passed Key to the Key value of the next matching K* entry in the scan.

 

Private Attributes

HashIndexFileindex
 
bool full_scan
 
Keysearch_key
 
BufferManagerbuf_mgr
 
PageId cur_pid
 
HashBucketPagecur_page
 
HashBucketPageScannerbucket_scanner
 
PageId cur_dir_pid
 
bool scan_complete
 

Detailed Description

HashIndexScanner: Scanner for Hash indicies. Different constructors are used to initiate different types of scans over indicies. getNext gets the the next matching tuple based on the type of scan

Constructor & Destructor Documentation

◆ HashIndexScanner() [1/2]

HashIndexScanner::HashIndexScanner ( HashIndexFile index)

Constructor for scanning all entries of the Index.

Precondition
Valid HashIndexFile* is provided as input.
Postcondition
IndexFileScanner object is constructed and initialized to do a scan of the entire index. cur_page, the first page of index K* entries is pinned if file is not empty.
Parameters
indexIndexFile object to be scanned.

◆ HashIndexScanner() [2/2]

HashIndexScanner::HashIndexScanner ( HashIndexFile index,
Key key_val 
)

Constructor for equality scan, this scan is over all K* entries with a matching key value to the passed key_val.

Precondition
Valid IndexFile and Key are provided as input.
Postcondition
HashIndexScanner object is constructed and initialized to do a scan of K* index entries with a matching key value. cur_page, the first page of index K* entries is pinned if file is not empty. Its key field is initialized to the passed key_val (a caller cannot reuse this Key object safely until the HashIndex Scanner is destroyed)
Parameters
indexIndexFile object to be scanned.
key_valKey value on which to do the equality scan

◆ ~HashIndexScanner()

HashIndexScanner::~HashIndexScanner ( )

Destructor.

Precondition
If the end of the Index scan has not been reached, cur_page is pinned.
Postcondition
cur_page is released.

Member Function Documentation

◆ getNext() [1/2]

RecordId HashIndexScanner::getNext ( )

Returns RecordId of the next matching K* in the scan.

This is the getNext method to use if you only need the RID of the next matching entry and do not also want the key value of the next matching K* entry in the scan.

Returns
Next RecordId, or INVALID_RECORD_ID if the end of the scan is reached.

◆ getNext() [2/2]

RecordId HashIndexScanner::getNext ( Key key)

Returns RecordId of the next matching K* and sets the data part of the passed Key to the Key value of the next matching K* entry in the scan.

This version of getNext should be used when the values of the key part of the K* entry are needed by the caller (for some non-equality searches this may be the case).

Precondition
the caller passes in a Key object that has been initialized to match the Key type of the index and with appropriate data field capacity to store the largest (in num bytes) key value (this function doesn't check capacity) TODO: should this function test if passed Key object is formatted correctly to store copy of Key value??
Postcondition
RecordId of the next Record is returned and data of the passed Key object is initialized to that of the next Key part of the next K* entry in the scan. If there are no more records in the Index scan, INVALID_RECORD_ID is returned.
Returns
Next RecordId, or INVALID_RECORD_ID if the end of the scan is reached.

Member Data Documentation

◆ bucket_scanner

HashBucketPageScanner* HashIndexScanner::bucket_scanner
private

Scanner over a hash bucket page

◆ buf_mgr

BufferManager* HashIndexScanner::buf_mgr
private

Pointer to the BufferManager of SwatDB (for retrieving/pinning pages).

◆ cur_dir_pid

PageId HashIndexScanner::cur_dir_pid
private

PageId of the Current Directory Page (useful for the full index scan)

◆ cur_page

HashBucketPage* HashIndexScanner::cur_page
private

Hash Bucket object that contains the latest Record scanned. if this is equal to nullptr then the scan is complete

◆ cur_pid

PageId HashIndexScanner::cur_pid
private

PageId of the Page that contains the latest Record scanned. if this is equal to INVALID_PAGE_ID then the scan is complete.

◆ full_scan

bool HashIndexScanner::full_scan
private

set to true if this is a full scan of the index

◆ index

HashIndexFile* HashIndexScanner::index
private

Pointer to the HashIndexFile to be scanned.

◆ scan_complete

bool HashIndexScanner::scan_complete
private

set to true if the scan is done

◆ search_key

Key* HashIndexScanner::search_key
private

The search Key value on which to scan for matches. Because hash indexes don't support range scans, and only support EQUAL Comp operators, we only need to store the search Key.

This stores a copy of the value passed to the constructor.


The documentation for this class was generated from the following file: