Closed GoogleCodeExporter closed 9 years ago
} strs.clear();
After this, your hash keys and values are dangling pointers.
If your hash_map is from string to string, you shouldn't have this problem.
Original comment by csilv...@gmail.com
on 17 Jan 2012 at 11:10
Thanks for the timely response.
I changed all the const char* to string and I get this error when I leave
PoS.set_empty_key(NULL);
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid
When i change the above line to PoS.set_empty_key(string()); I get the
following error
dict: /usr/include/google/sparsehash/densehashtable.h:930:
std::pair<google::dense_hashtable_iterator<V, K, HF, ExK, SetK, EqK, A>, bool>
google::dense_hashtable<Value, Key, HashFcn, ExtractKey, SetKey, EqualKey,
Alloc>::insert_noresize(google::dense_hashtable<Value, Key, HashFcn,
ExtractKey, SetKey, EqualKey, Alloc>::const_reference) [with Value =
std::pair<const std::basic_string<char>, std::basic_string<char> >, Key =
std::basic_string<char>, HashFcn = std::tr1::hash<std::basic_string<char> >,
ExtractKey = google::dense_hash_map<std::basic_string<char>,
std::basic_string<char>, std::tr1::hash<std::basic_string<char> >,
eqstr>::SelectKey, SetKey = google::dense_hash_map<std::basic_string<char>,
std::basic_string<char>, std::tr1::hash<std::basic_string<char> >,
eqstr>::SetKey, EqualKey = eqstr, Alloc =
google::libc_allocator_with_realloc<std::pair<const std::basic_string<char>,
std::basic_string<char> > >, google::dense_hashtable<Value, Key, HashFcn,
ExtractKey, SetKey, EqualKey, Alloc>::const_reference = const std::pair<const
std::basic_string<char>, std::basic_string<char> >&]: Assertion
`(!settings.use_empty() || !equals(get_key(obj), get_key(val_info.emptyval)))
&& "Inserting the empty key"' failed.
Original comment by rmyeid
on 17 Jan 2012 at 11:20
Yes, NULL is not a valid value for a string.
Original comment by csilv...@gmail.com
on 17 Jan 2012 at 11:39
What about the second error when I change the above line to
PoS.set_empty_key(string());
Original comment by rmyeid
on 17 Jan 2012 at 11:42
} EqualKey = eqstr
You still have this, which is wrong when the key is a string.
Original comment by csilv...@gmail.com
on 17 Jan 2012 at 11:51
I am attaching the working code, just as a reference for anyone who could be
stuck with the same issue.
Original comment by rmyeid
on 20 Jan 2012 at 9:27
Attachments:
Original issue reported on code.google.com by
rmyeid
on 17 Jan 2012 at 11:05