can't print the variable in vector

Hello,
I am in the first data structure (hash table) I insert the data, each filled cell is connected to a disjoint set precisely in the other class.
the problem arises when I try to print a certain data, I can take the pointer from the first structure (hash table) to the second structure (disjointset), but if I try to print it gives me an error on the "singleValue ()" function near " t (x) ".
error: no overloaded function instance "std :: vector <_Ty, _Alloc> :: at [with _Ty = TreeNode *, _Alloc = std :: allocator <TreeNode *>]" corresponding to the list of arguments - types of argument are: (disjointset) - type of object: std :: vector <TreeNode *, std :: allocator <TreeNode * >>

1
2
3
4
5
6
7
8
9
10
class nodo
{
private:
    int key;
    disjointset *root;
public:

//methods

};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class hashtable{
    private:
        int m,count = 0;
        vector<state> *S;
        vector<nodo*> *T;

    public:
        hashtable(int size)
        {
            this->m = size;
            this->S = new vector<state> (this->m, EMPTY);
            this->T = new vector<nodo*> (this->m, nullptr);
        }


        disjointset* getElement(int key);
}


1
2
3
4
5
6
disjointset* hashtable::getElement(int key)
{
    int element = this->search(key);

    return this->T->at(element)->getNodoS();
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class TreeNode //struct albero
{
private:
    int key;
    string value;
    int rango;
    TreeNode *parent;
public:
    TreeNode(int key, string value)
    {
        this->key=key;
        this->value=value;
        this->rango=0;
        this->parent=this;
    }
//methods
}


1
2
3
4
5
6
7
8
9
10
11
class disjointset
{
private:
    vector<TreeNode*> *D;//vector del nodo tree
public:
    disjointset(){ this->D = new vector<TreeNode*> (); };

    string singleValue(disjointset* x) { return this->D->at(x) ; }

//methods
}


can help me ?
I think you've overcomplicated this. It's not even clear to me what you're trying to store in your hash table. In your code:
A hash table has a vector of nodo's
A nodo has a pointer to a disjointset.
A disjointset has a vector of TreeNodes
A TreeNode has a parent, but no children?
So is a TreeNode what you're storing in the hash table? A key, value, and range? Is that an albero?

And why all the pointers all over the place? They seem unnecessary.

This hash table is a vector of buckets.
A bucket is a list of items.

in my hash table, I register the key (I do it in other functions where everything works) then my hash table has a pointer that points to a treenode which has a father and then later if you make a union it will have children
Why are these pointers instead of member variables?
nodo::root
hashtable::S
hashtable::T
disjointset::D

Is there every a time that any of these are nullptr?
because he is necessary for make structure
because he is necessary for make structure
No they aren't. In C++, classes can contain member variables directly. This is usually the preferred way to do it.

TreeNode and disjointset seem unnecessary to me. Why not do it like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <string>
#include <list>
#include <vector>

using std::string;
using std::list;
using std::vector;

class nodo {
public:
    int key;
    string value;
    int rango;
};

class hashtable {
private:
    int count = 0;		// use T.size() instead of m
    vector<list<nodo>> buckets;	// each bucket is a list of nodos

    public:
    hashtable(int size) : count(0), buckets(size)
    {}

    nodo *find(int key);
    void add(const nodo &n);	// add a copy of n to the hash table
};

// Return a pointer to the item with the same key. The pointer remains
// valid until you modify the hash table.
nodo *
hashtable::find(int key)
{
    int hashVal = key % buckets.size(); // get the hash value

    // for each item in the corresponding list. Note that we iterate
    // through them with a reference. This is important because we're
    // returning a pointer to the item, so we need to return a pointer
    // to the actual item in the list.
    for ( nodo &item : buckets[hashVal]) {
	if (item.key == key) {
	    return &item;
	}
    }
    // If you get here, you didn't find it.
    return nullptr;
}

void
hashtable::add(const nodo &n)
{
    int hashVal = n.key % buckets.size(); // get the hash value
    buckets[hashVal].push_front(n);
    ++count;
}




this is open adressing hash table, double hash and disjoint set is a radical tree, all have some features, can't remove
Topic archived. No new replies allowed.