--- deliantra/server/include/util.h 2010/07/02 02:00:47 1.110 +++ deliantra/server/include/util.h 2010/07/06 20:15:13 1.112 @@ -513,12 +513,13 @@ // with good distribution. // FNV-1a is faster on many cpus because the multiplication // runs concurrently with the looping logic. + // we modify the hash a bit to improve its distribution uint32_t hash = STRHSH_NULL; while (*s) hash = (hash ^ *s++) * 16777619U; - return hash; + return hash ^ (hash >> 16); } static inline uint32_t @@ -643,6 +644,74 @@ } }; +///////////////////////////////////////////////////////////////////////////// + +// something like a vector or stack, but without +// out of bounds checking +template +struct fixed_stack +{ + T *data; + int size; + int max; + + fixed_stack () + : size (0), data (0) + { + } + + fixed_stack (int max) + : size (0), max (max) + { + data = salloc (max); + } + + void reset (int new_max) + { + sfree (data, max); + size = 0; + max = new_max; + data = salloc (max); + } + + void free () + { + sfree (data, max); + data = 0; + } + + ~fixed_stack () + { + sfree (data, max); + } + + T &operator[](int idx) + { + return data [idx]; + } + + void push (T v) + { + data [size++] = v; + } + + T &pop () + { + return data [--size]; + } + + T remove (int idx) + { + T v = data [idx]; + + data [idx] = data [--size]; + + return v; + } +}; + +///////////////////////////////////////////////////////////////////////////// + // basically does what strncpy should do, but appends "..." to strings exceeding length // returns the number of bytes actually used (including \0) int assign (char *dst, const char *src, int maxsize);