Spooky hash, smarter animqueue diffs
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "streambuffer.hpp"
|
||||
#include "spookyv2.hpp"
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
@@ -151,6 +152,12 @@ void StreamBuffer::write_double(double d) {
|
||||
write_cursor_ += 8;
|
||||
}
|
||||
|
||||
void StreamBuffer::write_hashvalue(const util::HashValue &hv) {
|
||||
make_space(16);
|
||||
memcpy(write_cursor_, &hv, 16);
|
||||
write_cursor_ += 16;
|
||||
}
|
||||
|
||||
void StreamBuffer::write_bytes(const char *s, int64_t len) {
|
||||
make_space(len);
|
||||
memcpy(write_cursor_, s, len);
|
||||
@@ -224,6 +231,14 @@ int64_t StreamBuffer::read_int64() {
|
||||
return v;
|
||||
}
|
||||
|
||||
util::HashValue StreamBuffer::read_hashvalue() {
|
||||
check_available(16);
|
||||
util::HashValue hv;
|
||||
memcpy(&hv, read_cursor_, 16);
|
||||
read_cursor_ += 16;
|
||||
return hv;
|
||||
}
|
||||
|
||||
float StreamBuffer::read_float() {
|
||||
check_available(4);
|
||||
float f;
|
||||
@@ -296,6 +311,13 @@ void StreamBuffer::unwrite_to(int64_t wr_count) {
|
||||
write_cursor_ = buf_lo_ + (wr_count - pre_read_count_);
|
||||
}
|
||||
|
||||
util::HashValue StreamBuffer::hash() const {
|
||||
uint64_t hash1 = 0x82A7912E7893AC87;
|
||||
uint64_t hash2 = 0x81D402740DE458F3;
|
||||
SpookyHash::Hash128(read_cursor_, write_cursor_ - read_cursor_, &hash1, &hash2);
|
||||
return std::make_pair(hash1, hash2);
|
||||
}
|
||||
|
||||
int StreamBuffer::lua_writer(lua_State *L, const void* p, size_t sz, void* ud) {
|
||||
StreamBuffer *sb = (StreamBuffer *)ud;
|
||||
sb->write_bytes((const char *)p, sz);
|
||||
|
||||
Reference in New Issue
Block a user