Merge changes from The Witness.
This commit is contained in:
@ -46,7 +46,7 @@ namespace nv
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void construct(T * restrict ptr, uint new_size, uint old_size, const T & value) {
|
||||
void construct(T * restrict ptr, uint new_size, uint old_size, const T & elem) {
|
||||
for (uint i = old_size; i < new_size; i++) {
|
||||
new(ptr+i) T(elem); // placement new
|
||||
}
|
||||
@ -498,7 +498,7 @@ namespace nv
|
||||
}
|
||||
|
||||
for (uint i = 0; i < p.m_size; i++) {
|
||||
s << buffer()[i];
|
||||
s << p.buffer()[i];
|
||||
}
|
||||
|
||||
return s;
|
||||
|
@ -416,6 +416,9 @@ namespace nv
|
||||
|
||||
if (s.isLoading()) {
|
||||
map.clear();
|
||||
if(entry_count == 0) {
|
||||
return s;
|
||||
}
|
||||
map.entry_count = entry_count;
|
||||
map.size_mask = nextPowerOfTwo(entry_count) - 1;
|
||||
map.table = malloc<Entry>(map.size_mask + 1);
|
||||
@ -468,6 +471,13 @@ namespace nv
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Swap the members of this vector and the given vector.
|
||||
friend void swap(HashMap<T, U, H, E> & a, HashMap<T, U, H, E> & b)
|
||||
{
|
||||
swap(a.entry_count, b.entry_count);
|
||||
swap(a.size_mask, b.size_mask);
|
||||
swap(a.table, b.table);
|
||||
}
|
||||
|
||||
private:
|
||||
static const uint TOMBSTONE_HASH = (uint) -1;
|
||||
|
@ -299,6 +299,8 @@ namespace nv
|
||||
}
|
||||
//@}
|
||||
|
||||
const uint8 * ptr() const { return m_ptr; }
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
@ -105,6 +105,19 @@ namespace nv
|
||||
return h;
|
||||
}
|
||||
|
||||
// Note that this hash does not handle NaN properly.
|
||||
inline uint sdbmFloatHash(const float * f, uint count, uint h = 5381)
|
||||
{
|
||||
for (uint i = 0; i < count; i++) {
|
||||
//nvDebugCheck(nv::isFinite(*f));
|
||||
union { float f; uint32 i; } x = { *f };
|
||||
if (x.i == 0x80000000) x.i = 0;
|
||||
h = sdbmHash(&x, 4, h);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
// Some hash functors:
|
||||
template <typename Key> struct Hash
|
||||
{
|
||||
@ -120,6 +133,12 @@ namespace nv
|
||||
{
|
||||
uint operator()(uint x) const { return x; }
|
||||
};
|
||||
template <> struct Hash<float>
|
||||
{
|
||||
uint operator()(float f) const {
|
||||
return sdbmFloatHash(&f, 1);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Key> struct Equal
|
||||
{
|
||||
|
Reference in New Issue
Block a user