fix forward declarations

This commit is contained in:
Krishna Vedala 2020-07-29 12:46:29 -04:00
parent 7d3adb0023
commit 842c5fb251
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7
3 changed files with 17 additions and 16 deletions

View File

@ -15,8 +15,8 @@ namespace { // keep the code local to this file by assigning them to an unnamed
// fwd declarations // fwd declarations
using Entry = struct Entry; using Entry = struct Entry;
bool putProber(Entry entry, int key); bool putProber(const Entry& entry, int key);
bool searchingProber(Entry entry, int key); bool searchingProber(const Entry& entry, int key);
void add(int key); void add(int key);
// Undocumented globals // Undocumented globals
@ -112,7 +112,7 @@ int doubleHash(int key, bool searching) {
* @returns `true` if key is not present or is a `toumb` * @returns `true` if key is not present or is a `toumb`
* @returns `false` is already occupied * @returns `false` is already occupied
*/ */
bool putProber(Entry entry, int key) { bool putProber(const Entry& entry, int key) {
if (entry.key == notPresent || entry.key == tomb) { if (entry.key == notPresent || entry.key == tomb) {
return true; return true;
} }
@ -125,7 +125,7 @@ bool putProber(Entry entry, int key) {
* @returns `true` if found * @returns `true` if found
* @returns `false` if not found * @returns `false` if not found
*/ */
bool searchingProber(Entry entry, int key) { bool searchingProber(const Entry& entry, int key) {
if (entry.key == key) { if (entry.key == key) {
return true; return true;
} }

View File

@ -18,15 +18,10 @@ using std::string;
namespace { // keep the code local to this file by assigning them to an unnamed namespace { // keep the code local to this file by assigning them to an unnamed
// namespace // namespace
/** Node object that holds key */
struct Entry {
explicit Entry(int key = notPresent) : key(key) {} ///< constructor
int key; ///< key value
};
// fwd declarations // fwd declarations
bool putProber(Entry entry, int key); using Entry = struct Entry;
bool searchingProber(Entry entry, int key); bool putProber(const Entry& entry, int key);
bool searchingProber(const Entry& entry, int key);
void add(int key); void add(int key);
// Undocumented globals // Undocumented globals
@ -37,6 +32,12 @@ int tomb = -1;
int size; int size;
bool rehashing; bool rehashing;
/** Node object that holds key */
struct Entry {
explicit Entry(int key = notPresent) : key(key) {} ///< constructor
int key; ///< key value
};
/** /**
* @brief Hash a key. Uses the STL library's `std::hash()` function. * @brief Hash a key. Uses the STL library's `std::hash()` function.
* *

View File

@ -18,8 +18,8 @@ namespace { // keep the code local to this file by assigning them to an unnamed
// fwd declarations // fwd declarations
using Entry = struct Entry; using Entry = struct Entry;
bool putProber(Entry entry, int key); bool putProber(const Entry& entry, int key);
bool searchingProber(Entry entry, int key); bool searchingProber(const Entry& entry, int key);
void add(int key); void add(int key);
// globals // globals
@ -87,7 +87,7 @@ int quadraticProbe(int key, bool searching) {
} }
// Finds empty spot // Finds empty spot
bool putProber(Entry entry, int key) { bool putProber(const Entry& entry, int key) {
if (entry.key == notPresent || entry.key == tomb) { if (entry.key == notPresent || entry.key == tomb) {
return true; return true;
} }
@ -95,7 +95,7 @@ bool putProber(Entry entry, int key) {
} }
// Looks for a matching key // Looks for a matching key
bool searchingProber(Entry entry, int key) { bool searchingProber(const Entry& entry, int key) {
if (entry.key == key) { if (entry.key == key) {
return true; return true;
} }