Category : hashmap

I have to create a custom hash-table that uses linear probing for collision resolution. The hash table stores a vector of structs. The struct stores the pair for each (key, value) which are templated along with a status for empty, occupied, and deleted. I am having trouble with my insert function using the std::hash() function ..

Read more

my code: class Solution { public: int lengthOfLongestSubstring(string s) { if(s.length()==0){ return 0; } unordered_map<char, int> map; int j=0,c=0,x=c,st=0; for(int i=0;i<s.length();i++){ if(map.find(s[i])==map.end()){ map[s[i]]++; x++; continue; } else{ auto it1=map.find(s[j]); auto it2=map.find(s[i-1]); map.erase(it1, it2); j++; i=j-1; if(x>c){ c=x; x=0; continue; } } } if(x>c){ c=x; } return c; } }; and getting the following error: Line ..

Read more

I wanted to create a hashmap with the key as a pair but of the pair values is of a struct that I have defined. Something like below. unordered_map<pair<node*,int>,int> m; The compiler is throwing an error. What am I doing wrong. If this is not possible is there an alternative? error is – /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/unordered_map.h:141:7: note: ..

Read more

def recursiveDict(): return collections.defaultdict(recursiveDict) # I can create a dictionary like the following dic = recursiveDict() dic[‘a’] = 1 dic[‘a’][‘a’] = 1 dic[‘a’][‘a’][‘a’] = 1 dic[‘a’][‘a’][‘a’][‘a’] = 1 and so on…. I have returned to work with C++ after working for 4 years with Python and other dynamic languages. I wanted to be able to ..

Read more