Ok I started writing this program for a school project in Eclipse in windows and now shifting to vim in UNIX and I am getting a bunch of errors. I am currently trying to figure out the top two errors (And yes the funky characters are what I see).

Here is my stuff:

My makefile:

main: *.cpp *.h
        g++ -o LSL *.cpp

clean:
        rm -f *.o LSL*

Here are the errors when I run make:

unixserver:Lab3> make
g++ -o LSL *.cpp
ClosedHash.h:20: error: âHTâ has not been declared
ClosedHash.h:20: error: âposâ was not declared in this scope
ClosedHash.cpp: In destructor âvirtual ClosedHash::~ClosedHash()â:
ClosedHash.cpp:16: error: expected primary-expression before â;â token
ClosedHash.cpp: In function âbool insert(int, int)â:
ClosedHash.cpp:106: error: âgetKeyâ was not declared in this scope
ClosedHash.cpp:106: error: âhâ was not declared in this scope
ClosedHash.cpp:107: error: âEMPTYâ was not declared in this scope
ClosedHash.cpp:107: error: âHTâ was not declared in this scope
ClosedHash.cpp:107: error: âcheckHashâ was not declared in this scope
ClosedHash.cpp:108: error: âTOMBSTONEâ was not declared in this scope
ClosedHash.cpp:110: error: âprobeSeqâ was not declared in this scope
ClosedHash.cpp:110: error: âmaxSizeâ was not declared in this scope
ClosedHash.cpp:113: error: âHTâ was not declared in this scope
ClosedHash.cpp: In member function âvirtual bool ClosedHash::remove(int)â:
ClosedHash.cpp:126: error: âKâ was not declared in this scope
ClosedHash.cpp:127: error: âHTâ was not declared in this scope
ClosedHash.cpp:130: error: âMâ was not declared in this scope
ClosedHash.cpp:131: error: âHTâ was not declared in this scope
ClosedHash.cpp:132: error: âeâ was not declared in this scope
ClosedHash.cpp: At global scope:
ClosedHash.cpp:138: error: âHTâ has not been declared
ClosedHash.cpp:138: error: âposâ was not declared in this scope
ClosedHash.cpp:157: error: non-member function âint count()â cannot have cv-qualifier
ClosedHash.cpp: In function âint count()â:
ClosedHash.cpp:158: error: invalid conversion from âint (*)()constâ to âintâ
ClosedHash.cpp: At global scope:
ClosedHash.cpp:162: error: non-member function âfloat alpha()â cannot have cv-qualifier
ClosedHash.cpp: In function âfloat alpha()â:
ClosedHash.cpp:163: error: âmaxSizeâ was not declared in this scope
ClosedHash.cpp: At global scope:
ClosedHash.cpp:169: error: non-member function âbool full()â cannot have cv-qualifier
ClosedHash.h:20: error: âHTâ has not been declared
ClosedHash.h:20: error: âposâ was not declared in this scope
main.cpp: In function âint main()â:
main.cpp:172: error: no matching function for call to âClosedHash::ClosedHash(int)â
ClosedHash.h:16: note: candidates are: ClosedHash::ClosedHash()
ClosedHash.h:13: note:                 ClosedHash::ClosedHash(const ClosedHash&)
make: *** [main] Error 1
unixserver:Lab3> 

Here are my code files:

Hash.h:

#ifndef __Hash_h__
#define __Hash_h__

class Hash {

protected: // Protected since children need access to these static properties.

  static const int EMPTY = -1;
  static const int TOMBSTONE = -2;

 public:
  // Insert an integer into the hash.  Return true if successful,
  // false if there are no more slots in the hash, or the integer
  // is already found.  Store the number of collisions in the
  // variable 'collisions'.
  virtual bool insert(int newValue, int &collisions) = 0;

  // Find an integer value in the hash.  Return true if found,
  // false if not.  Store the number of probes in the variable
  // 'probes'.
  virtual bool find(int searchValue, int &probes) const = 0;

  // Delete an integer from the hash.  Return true if successful,
  // false if unsuccessful.
  virtual bool remove(int delValue) = 0;

  // Return the number of items currently in the hash.
  virtual int count() const = 0;

  // Return the current alpha value of the hash.
  virtual float alpha() const = 0;

  // Returns true if the hash is full, otherwise false.
  // NB: This is only meaningful in a closed hash table.
  virtual bool full() const = 0;
};

#endif

ClosedHash.h:

#ifndef _CLOSEDHASH_H
#define _CLOSEDHASH_H

#include "Hash.h"

class ClosedHash : public Hash {

public:
    ClosedHash();
    bool insert(int newValueId, int &collisions);
    bool find(int searchValue, int &probes) const;
    bool remove(int delValue);
    bool checkHash(int EMPTY, HT[pos]);
    bool checkKey();
    bool probeSeq();
    int count() const;
    float alpha() const;
    bool full() const;
    int getKey(int ID);

    virtual ~ClosedHash();
    unsigned int h(int key) const;
    unsigned int h2(int key) const;

private:
    const int maxSize;
};

#endif  /* _CLOSEDHASH_H */

ClosedHash.cpp:

#include "ClosedHash.h"

void ClosedHash(int maxSize) {
    int hashTable[maxSize]; // I think this is my problem - commented out and Changed to HT[masSize] next line
    //int HT[maxSize];
}

ClosedHash::~ClosedHash() {
    delete[] ClosedHash;
}

unsigned int ClosedHash::h(int key) const {
  unsigned int hash = 0;      // The hash value starts at 0
  unsigned int keyarr = key;  // A copy of the key

  // We will treat the key (an integer) as an array of 4
  // unsigned characters
  unsigned char *keyptr = (unsigned char *) &keyarr;

  // Mix each 8-bit character into the hash
  for (int i = 0; i < (sizeof(int)); i++) {

    // This is the combining step:
    hash += keyptr[i];

    // This is the mixing step:
    hash += (hash << 10);
    hash ^= (hash >> 6);
  }

  // After all the bits of the key have been mixed in,
  // ensure that they are properly distributed throughout
  // the final hash value:
  hash += (hash << 3);
  hash ^= (hash >> 11);
  hash += (hash << 15);

  // This last line assumes the you have a data member
  // or constant in class ClosedHash called maxSize.  This
  // is the value M (the number of buckets in the hash).  This
  // can be a private data element or constant.
  return hash % maxSize;
}

//  ****
//  For comments, see h(), above!
//  Also see the comments near the end of h2().
//  ****

unsigned int ClosedHash::h2(int key) const {
  unsigned int hash = 0;
  unsigned int keyarr = key;
  unsigned char *keyptr = (unsigned char *) &keyarr;

  for (int i = 0; i < sizeof(int); i++) {
    hash += keyptr[i];
    hash += (hash << 9);
    hash ^= (hash >> 5);
  }
  hash += (hash << 3);
  hash ^= (hash >> 11);
  hash += (hash << 15);

  // The following code ensures that the value of h2(k) will be
  // odd, which should be coprime with the size of the closed
  // hash (32,768 == 2^15).
  return (((hash * 2) + 1) % maxSize);
}

// Insert ID into hash table HT

bool insert(int ID, int collisions) {
    int home; // Home position for ID
    int pos = home = h(getKey(ID)); // Init probe sequence
    for (int i = 1; (!(checkHash(EMPTY, HT[pos])) &&
            !(checkHash(TOMBSTONE, HT[pos]))); i++) {
        // TODO Shouldn't I replace getKey(ID) with just ID?
        pos = (home + probeSeq(getKey(ID), i)) % maxSize; // Follow probes | function p is the probe sequence
        if (checkHash(ID, HT[pos])) return false; // Duplicate
    }
    HT[pos] = ID; // Insert ID
    return true;
}

bool ClosedHash::find(int searchValue, int &probes) const {

}

// Search for and delete the record with Key K

bool ClosedHash::remove(int delValue) {
    int home; // Home position for K
    // Initial posit on probe sequence
    int pos = home = h(K);
    for (int i = 1; !checkKey(K, HT[pos]) &&
            !checkHash(EMPTY, HT[pos]); i++)
        // Next on probe sequence
        pos = (home + probeSeq(K, i)) % M;
    if (checkKey(K, HT[pos])) { // Found it
        e = HT[pos];
        HT[pos] = TOMBSTONE; // Delete it
        return true;
    } else return false; // K not in hash table
}

bool checkHash(int EMPTY, HT[pos]){
    // TODO
}

bool checkKey() {
    // TODO
}

bool probeSeq() {
    // TODO
}


// TODO fix up the below 4 functions...
int getKey(int ID) {
    return ID; //return the key of the requested ID;
}

// Return the number of items currently in the hash.
int count() const {
    return count;
}

// Return the current alpha value of the hash.
float alpha() const {
    return count / maxSize;

}

  // Returns true if the hash is full, otherwise false.
  // NB: This is only meaningful in a closed hash table.
bool full() const {
    //if hash is full return true else return false;
    //
    // if hash.size() == maxSize return true; // How do I size of hash??
    // else return false; // false == hash is not full
}

Recommended Answers

All 2 Replies

Well, maybe you should start by trying to locate the declarations of HT and pos, because, as the compiler says, they are not declared in that scope. For your function prototype to be valid, HT should be a type and pos should be a #define. I see no such thing anywhere. I believe you simply made a mistake declaring that function. Care to explain what you think that function-declaration means?

well there are a missing
ClosedHash::
before some of your functions try fixing that up , should clear a few errors

... ClosedHash::insert(....)
{...}

report back with your new errors
good luck ^^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.