http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/IpMapConf.cc ---------------------------------------------------------------------- diff --git a/lib/ts/IpMapConf.cc b/lib/ts/IpMapConf.cc index bb54ae5..1c60044 100644 --- a/lib/ts/IpMapConf.cc +++ b/lib/ts/IpMapConf.cc @@ -23,9 +23,9 @@ // Copied from IPRange.cc for backwards compatibility. -# include <ts/IpMap.h> -# include <ts/IpMapConf.h> -# include <ts/ink_memory.h> +#include <ts/IpMap.h> +#include <ts/IpMapConf.h> +#include <ts/ink_memory.h> static size_t const ERR_STRING_LEN = 256; static size_t const MAX_LINE_SIZE = 2048; @@ -37,11 +37,11 @@ static size_t const MAX_LINE_SIZE = 2048; // addr [out] Destination for address. // err Buffer for error string (must be ERR_STRING_LEN big). int -read_addr(char *line, int n, int *i, sockaddr* addr, char* err) +read_addr(char *line, int n, int *i, sockaddr *addr, char *err) { int k; char dst[INET6_ADDRSTRLEN]; - char* src = line + *i; + char *src = line + *i; bool bracketed_p = false; // Allow enclosing brackets to be more consistent but @@ -50,11 +50,11 @@ read_addr(char *line, int n, int *i, sockaddr* addr, char* err) ++*i, ++src, bracketed_p = true; } - for (k = 0; k < INET6_ADDRSTRLEN && *i < n && (isxdigit(*src) || '.' == *src || ':' == *src) ; ++k, ++*i, ++src) { + for (k = 0; k < INET6_ADDRSTRLEN && *i < n && (isxdigit(*src) || '.' == *src || ':' == *src); ++k, ++*i, ++src) { dst[k] = *src; } - if (bracketed_p && (! (*i < n) || (']' != *src))) { + if (bracketed_p && (!(*i < n) || (']' != *src))) { snprintf(err, ERR_STRING_LEN, "Unclosed brackets"); return EINVAL; } @@ -73,13 +73,14 @@ read_addr(char *line, int n, int *i, sockaddr* addr, char* err) } char * -Load_IpMap_From_File(IpMap* map, int fd, const char *key_str) +Load_IpMap_From_File(IpMap *map, int fd, const char *key_str) { - char* zret = 0; + char *zret = 0; int fd2 = dup(fd); // dup to avoid closing the original file. - FILE* f = NULL; + FILE *f = NULL; - if (fd2 >= 0) f = fdopen(fd2, "r"); + if (fd2 >= 0) + f = fdopen(fd2, "r"); if (f != NULL) { zret = Load_IpMap_From_File(map, f, key_str); @@ -97,7 +98,8 @@ Load_IpMap_From_File(IpMap* map, int fd, const char *key_str) // line Source line. // n Line length. // offset Current offset -static inline bool skip_space(char* line, int n, int& offset ) +static inline bool +skip_space(char *line, int n, int &offset) { while (offset < n && isspace(line[offset])) ++offset; @@ -106,7 +108,7 @@ static inline bool skip_space(char* line, int n, int& offset ) // Returns 0 if successful, error string otherwise char * -Load_IpMap_From_File(IpMap* map, FILE* f, const char *key_str) +Load_IpMap_From_File(IpMap *map, FILE *f, const char *key_str) { int i, n, line_no; int key_len = strlen(key_str); @@ -122,7 +124,7 @@ Load_IpMap_From_File(IpMap* map, FILE* f, const char *key_str) ++line_no; n = strlen(line); // Find first white space which terminates the line key. - for ( i = 0 ; i < n && ! isspace(line[i]); ++i) + for (i = 0; i < n && !isspace(line[i]); ++i) ; if (i != key_len || 0 != strncmp(line, key_str, key_len)) continue; @@ -131,10 +133,10 @@ Load_IpMap_From_File(IpMap* map, FILE* f, const char *key_str) if (!skip_space(line, n, i)) break; - if (0 != read_addr(line, n, &i, &laddr.sa, err_buff)) { + if (0 != read_addr(line, n, &i, &laddr.sa, err_buff)) { char *error_str = (char *)ats_malloc(ERR_STRING_LEN); - snprintf(error_str, ERR_STRING_LEN, "Invalid input configuration (%s) at line %d offset %d - '%s'", err_buff, - line_no, i, line); + snprintf(error_str, ERR_STRING_LEN, "Invalid input configuration (%s) at line %d offset %d - '%s'", err_buff, line_no, i, + line); return error_str; } @@ -151,13 +153,11 @@ Load_IpMap_From_File(IpMap* map, FILE* f, const char *key_str) ++i; if (!skip_space(line, n, i)) { char *error_str = (char *)ats_malloc(ERR_STRING_LEN); - snprintf(error_str, ERR_STRING_LEN, "Invalid input (unterminated range) at line %d offset %d - '%s'", line_no, - i, line); + snprintf(error_str, ERR_STRING_LEN, "Invalid input (unterminated range) at line %d offset %d - '%s'", line_no, i, line); return error_str; } else if (0 != read_addr(line, n, &i, &raddr.sa, err_buff)) { char *error_str = (char *)ats_malloc(ERR_STRING_LEN); - snprintf(error_str, ERR_STRING_LEN, "Invalid input (%s) at line %d offset %d - '%s'", err_buff, line_no, i, - line); + snprintf(error_str, ERR_STRING_LEN, "Invalid input (%s) at line %d offset %d - '%s'", err_buff, line_no, i, line); return error_str; } map->mark(&laddr.sa, &raddr.sa); @@ -165,8 +165,7 @@ Load_IpMap_From_File(IpMap* map, FILE* f, const char *key_str) break; if (line[i] != ',') { char *error_str = (char *)ats_malloc(ERR_STRING_LEN); - snprintf(error_str, ERR_STRING_LEN, "Invalid input (expecting comma) at line %d offset %d - '%s'", line_no, - i, line); + snprintf(error_str, ERR_STRING_LEN, "Invalid input (expecting comma) at line %d offset %d - '%s'", line_no, i, line); return error_str; } ++i;
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/IpMapConf.h ---------------------------------------------------------------------- diff --git a/lib/ts/IpMapConf.h b/lib/ts/IpMapConf.h index 8ec0c7c..1895b49 100644 --- a/lib/ts/IpMapConf.h +++ b/lib/ts/IpMapConf.h @@ -26,6 +26,6 @@ class IpMap; // declare in name only. // Returns 0 if successful, error string otherwise -char* Load_IpMap_From_File(IpMap* map, int fd, char const* key_str); +char *Load_IpMap_From_File(IpMap *map, int fd, char const *key_str); // Returns 0 if successful, error string otherwise -char* Load_IpMap_From_File(IpMap* map, FILE* f, char const* key_str); +char *Load_IpMap_From_File(IpMap *map, FILE *f, char const *key_str); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/IpMapTest.cc ---------------------------------------------------------------------- diff --git a/lib/ts/IpMapTest.cc b/lib/ts/IpMapTest.cc index 14a8107..af9a6b2 100644 --- a/lib/ts/IpMapTest.cc +++ b/lib/ts/IpMapTest.cc @@ -25,27 +25,27 @@ #include <ts/TestBox.h> void -IpMapTestPrint(IpMap& map) { +IpMapTestPrint(IpMap &map) +{ printf("IpMap Dump\n"); - for ( IpMap::iterator spot(map.begin()), limit(map.end()) - ; spot != limit - ; ++spot - ) { + for (IpMap::iterator spot(map.begin()), limit(map.end()); spot != limit; ++spot) { ip_text_buffer ipb1, ipb2; - printf("%s - %s : %p\n", ats_ip_ntop(spot->min(), ipb1, sizeof ipb1), ats_ip_ntop(spot->max(), ipb2, sizeof(ipb2)), spot->data()); + printf("%s - %s : %p\n", ats_ip_ntop(spot->min(), ipb1, sizeof ipb1), ats_ip_ntop(spot->max(), ipb2, sizeof(ipb2)), + spot->data()); } printf("\n"); } -REGRESSION_TEST(IpMap_Basic)(RegressionTest* t, int /* atype ATS_UNUSED */, int* pstatus) { +REGRESSION_TEST(IpMap_Basic)(RegressionTest *t, int /* atype ATS_UNUSED */, int *pstatus) +{ TestBox tb(t, pstatus); IpMap map; - void* const markA = reinterpret_cast<void*>(1); - void* const markB = reinterpret_cast<void*>(2); - void* const markC = reinterpret_cast<void*>(3); - void* mark; // for retrieval + void *const markA = reinterpret_cast<void *>(1); + void *const markB = reinterpret_cast<void *>(2); + void *const markC = reinterpret_cast<void *>(3); + void *mark; // for retrieval in_addr_t ip5 = htonl(5), ip9 = htonl(9); in_addr_t ip10 = htonl(10), ip15 = htonl(15), ip20 = htonl(20); @@ -58,7 +58,7 @@ REGRESSION_TEST(IpMap_Basic)(RegressionTest* t, int /* atype ATS_UNUSED */, int* *pstatus = REGRESSION_TEST_PASSED; - map.mark(ip10,ip20,markA); + map.mark(ip10, ip20, markA); map.mark(ip5, ip9, markA); tb.check(map.getCount() == 1, "Coalesce failed"); tb.check(map.contains(ip9), "Range max not found."); @@ -93,10 +93,10 @@ REGRESSION_TEST(IpMap_Basic)(RegressionTest* t, int /* atype ATS_UNUSED */, int* tb.check(!map.contains(ip160), "Test 3 - unmark right edge still there."); map.clear(); - map.mark(ip20,ip20, markA); + map.mark(ip20, ip20, markA); tb.check(map.contains(ip20), "Map failed on singleton insert"); map.mark(ip10, ip200, markB); - mark=0; + mark = 0; map.contains(ip20, &mark); tb.check(mark == markB, "Map held singleton against range."); map.mark(ip100, ip120, markA); @@ -105,14 +105,15 @@ REGRESSION_TEST(IpMap_Basic)(RegressionTest* t, int /* atype ATS_UNUSED */, int* tb.check(map.getCount() == 1, "IpMap: Full range fill left extra ranges."); } -REGRESSION_TEST(IpMap_Unmark)(RegressionTest* t, int /* atype ATS_UNUSED */, int* pstatus) { +REGRESSION_TEST(IpMap_Unmark)(RegressionTest *t, int /* atype ATS_UNUSED */, int *pstatus) +{ TestBox tb(t, pstatus); IpMap map; -// ip_text_buffer ipb1, ipb2; - void* const markA = reinterpret_cast<void*>(1); + // ip_text_buffer ipb1, ipb2; + void *const markA = reinterpret_cast<void *>(1); IpEndpoint a_0, a_0_0_0_16, a_0_0_0_17, a_max; - IpEndpoint a_10_28_56_0,a_10_28_56_4, a_10_28_56_255; + IpEndpoint a_10_28_56_0, a_10_28_56_4, a_10_28_56_255; IpEndpoint a_10_28_55_255, a_10_28_57_0; IpEndpoint a_63_128_1_12; IpEndpoint a_loopback, a_loopback2; @@ -153,18 +154,19 @@ REGRESSION_TEST(IpMap_Unmark)(RegressionTest* t, int /* atype ATS_UNUSED */, int tb.check(map.contains(&a_0_0_0_17), "IpMap Unmark: Range unmark zero bounded range max+1 removed."); } -REGRESSION_TEST(IpMap_Fill)(RegressionTest* t, int /* atype ATS_UNUSED */, int* pstatus) { +REGRESSION_TEST(IpMap_Fill)(RegressionTest *t, int /* atype ATS_UNUSED */, int *pstatus) +{ TestBox tb(t, pstatus); IpMap map; ip_text_buffer ipb1, ipb2; - void* const allow = reinterpret_cast<void*>(0); - void* const deny = reinterpret_cast<void*>(~0); - void* const markA = reinterpret_cast<void*>(1); - void* const markB = reinterpret_cast<void*>(2); - void* const markC = reinterpret_cast<void*>(3); - void* mark; // for retrieval - - IpEndpoint a0,a_10_28_56_0,a_10_28_56_255,a3,a4; + void *const allow = reinterpret_cast<void *>(0); + void *const deny = reinterpret_cast<void *>(~0); + void *const markA = reinterpret_cast<void *>(1); + void *const markB = reinterpret_cast<void *>(2); + void *const markC = reinterpret_cast<void *>(3); + void *mark; // for retrieval + + IpEndpoint a0, a_10_28_56_0, a_10_28_56_255, a3, a4; IpEndpoint a_9_255_255_255, a_10_0_0_0, a_10_0_0_19, a_10_0_0_255, a_10_0_1_0; IpEndpoint a_10_28_56_4, a_max, a_loopback, a_loopback2; IpEndpoint a_10_28_55_255, a_10_28_57_0; @@ -205,10 +207,10 @@ REGRESSION_TEST(IpMap_Fill)(RegressionTest* t, int /* atype ATS_UNUSED */, int* ats_ip_pton("127.0.0.255", &a_loopback2); ats_ip_pton("63.128.1.12", &a_63_128_1_12); - map.fill(&a_10_28_56_0,&a_10_28_56_255,deny); - map.fill(&a0,&a_max,allow); + map.fill(&a_10_28_56_0, &a_10_28_56_255, deny); + map.fill(&a0, &a_max, allow); - tb.check(map.contains(&a_10_28_56_4,&mark), "IpMap Fill: Target not found."); + tb.check(map.contains(&a_10_28_56_4, &mark), "IpMap Fill: Target not found."); tb.check(mark == deny, "IpMap Fill: Expected deny, got allow at %s.", ats_ip_ntop(&a_10_28_56_4, ipb1, sizeof(ipb1))); map.clear(); @@ -216,12 +218,13 @@ REGRESSION_TEST(IpMap_Fill)(RegressionTest* t, int /* atype ATS_UNUSED */, int* tb.check(map.contains(&a_loopback), "IpMap fill: singleton not marked."); map.fill(&a0, &a_max, deny); - mark=0; + mark = 0; tb.check(map.contains(&a_loopback, &mark), "IpMap fill: singleton marking lost."); tb.check(mark == allow, "IpMap fill: overwrote existing singleton mark."); if (tb.check(map.begin() != map.end(), "IpMap fill: map is empty.")) { if (tb.check(++(map.begin()) != map.end(), "IpMap fill: only one range.")) { - tb.check(-1 == ats_ip_addr_cmp(map.begin()->max(), (++map.begin())->min()), "IpMap fill: ranges not disjoint [%s < %s].", ats_ip_ntop(map.begin()->max(), ipb1, sizeof(ipb1)), ats_ip_ntop((++map.begin())->min(), ipb2, sizeof(ipb2))); + tb.check(-1 == ats_ip_addr_cmp(map.begin()->max(), (++map.begin())->min()), "IpMap fill: ranges not disjoint [%s < %s].", + ats_ip_ntop(map.begin()->max(), ipb1, sizeof(ipb1)), ats_ip_ntop((++map.begin())->min(), ipb2, sizeof(ipb2))); } } @@ -251,20 +254,13 @@ REGRESSION_TEST(IpMap_Fill)(RegressionTest* t, int /* atype ATS_UNUSED */, int* map.fill(&a_0000_0001, &a_0000_0001, markA); map.fill(&a_0000_0000, &a_ffff_ffff, markB); - tb.check(map.contains(&a_0000_0000, &mark) && mark == markB, - "IpMap Fill[v6]: Zero address has bad mark."); - tb.check(map.contains(&a_ffff_ffff, &mark) && mark == markB, - "IpMap Fill[v6]: Max address has bad mark."); - tb.check(map.contains(&a_fe80_9d90, &mark) && mark == markA, - "IpMap Fill[v6]: 9d90 address has bad mark."); - tb.check(map.contains(&a_fe80_9d8f, &mark) && mark == markB, - "IpMap Fill[v6]: 9d8f address has bad mark."); - tb.check(map.contains(&a_fe80_9d9d, &mark) && mark == markA, - "IpMap Fill[v6]: 9d9d address has bad mark."); - tb.check(map.contains(&a_fe80_9d9e, &mark) && mark == markB, - "IpMap Fill[v6]: 9d9b address has bad mark."); - tb.check(map.contains(&a_0000_0001, &mark) && mark == markA, - "IpMap Fill[v6]: ::1 has bad mark."); + tb.check(map.contains(&a_0000_0000, &mark) && mark == markB, "IpMap Fill[v6]: Zero address has bad mark."); + tb.check(map.contains(&a_ffff_ffff, &mark) && mark == markB, "IpMap Fill[v6]: Max address has bad mark."); + tb.check(map.contains(&a_fe80_9d90, &mark) && mark == markA, "IpMap Fill[v6]: 9d90 address has bad mark."); + tb.check(map.contains(&a_fe80_9d8f, &mark) && mark == markB, "IpMap Fill[v6]: 9d8f address has bad mark."); + tb.check(map.contains(&a_fe80_9d9d, &mark) && mark == markA, "IpMap Fill[v6]: 9d9d address has bad mark."); + tb.check(map.contains(&a_fe80_9d9e, &mark) && mark == markB, "IpMap Fill[v6]: 9d9b address has bad mark."); + tb.check(map.contains(&a_0000_0001, &mark) && mark == markA, "IpMap Fill[v6]: ::1 has bad mark."); tb.check(map.getCount() == 10, "IpMap Fill[pre-refill]: Bad range count."); // These should be ignored by the map as it is completely covered for IPv6. @@ -277,19 +273,11 @@ REGRESSION_TEST(IpMap_Fill)(RegressionTest* t, int /* atype ATS_UNUSED */, int* map.fill(&a_fe80_9d90, &a_fe80_9d9d, markA); map.fill(&a_0000_0001, &a_0000_0001, markC); map.fill(&a_0000_0000, &a_ffff_ffff, markB); - tb.check(map.contains(&a_0000_0000, &mark) && mark == markB, - "IpMap Fill[v6-2]: Zero address has bad mark."); - tb.check(map.contains(&a_ffff_ffff, &mark) && mark == markB, - "IpMap Fill[v6-2]: Max address has bad mark."); - tb.check(map.contains(&a_fe80_9d90, &mark) && mark == markA, - "IpMap Fill[v6-2]: 9d90 address has bad mark."); - tb.check(map.contains(&a_fe80_9d8f, &mark) && mark == markB, - "IpMap Fill[v6-2]: 9d8f address has bad mark."); - tb.check(map.contains(&a_fe80_9d9d, &mark) && mark == markA, - "IpMap Fill[v6-2]: 9d9d address has bad mark."); - tb.check(map.contains(&a_fe80_9d9e, &mark) && mark == markB, - "IpMap Fill[v6-2]: 9d9b address has bad mark."); - tb.check(map.contains(&a_0000_0001, &mark) && mark == markC, - "IpMap Fill[v6-2]: ::1 has bad mark."); - + tb.check(map.contains(&a_0000_0000, &mark) && mark == markB, "IpMap Fill[v6-2]: Zero address has bad mark."); + tb.check(map.contains(&a_ffff_ffff, &mark) && mark == markB, "IpMap Fill[v6-2]: Max address has bad mark."); + tb.check(map.contains(&a_fe80_9d90, &mark) && mark == markA, "IpMap Fill[v6-2]: 9d90 address has bad mark."); + tb.check(map.contains(&a_fe80_9d8f, &mark) && mark == markB, "IpMap Fill[v6-2]: 9d8f address has bad mark."); + tb.check(map.contains(&a_fe80_9d9d, &mark) && mark == markA, "IpMap Fill[v6-2]: 9d9d address has bad mark."); + tb.check(map.contains(&a_fe80_9d9e, &mark) && mark == markB, "IpMap Fill[v6-2]: 9d9b address has bad mark."); + tb.check(map.contains(&a_0000_0001, &mark) && mark == markC, "IpMap Fill[v6-2]: ::1 has bad mark."); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/Layout.cc ---------------------------------------------------------------------- diff --git a/lib/ts/Layout.cc b/lib/ts/Layout.cc index 6e1dfdb..8669953 100644 --- a/lib/ts/Layout.cc +++ b/lib/ts/Layout.cc @@ -30,7 +30,8 @@ Layout * Layout::get() { if (layout == NULL) { - ink_assert("need to call create_default_layout before accessing" "default_layout()"); + ink_assert("need to call create_default_layout before accessing" + "default_layout()"); } return layout; } @@ -55,8 +56,7 @@ layout_relative(const char *root, const char *file) ink_error("Cannot merge path '%s' above the root '%s'\n", file, root); } else if (err == E2BIG) { ink_error("Exceeding file name length limit of %d characters\n", PATH_NAME_MAX); - } - else { + } else { // TODO: Make some pretty errors. ink_error("Cannot merge '%s' with '%s' error=%d\n", file, root, err); } @@ -76,16 +76,14 @@ Layout::relative(char *buf, size_t bufsz, const char *file) { char path[PATH_NAME_MAX]; - if (ink_filepath_merge(path, PATH_NAME_MAX, prefix, file, - INK_FILEPATH_TRUENAME)) { + if (ink_filepath_merge(path, PATH_NAME_MAX, prefix, file, INK_FILEPATH_TRUENAME)) { int err = errno; // Log error if (err == EACCES) { ink_error("Cannot merge path '%s' above the root '%s'\n", file, prefix); } else if (err == E2BIG) { ink_error("Exceeding file name length limit of %d characters\n", PATH_NAME_MAX); - } - else { + } else { // TODO: Make some pretty errors. ink_error("Cannot merge '%s' with '%s' error=%d\n", file, prefix, err); } @@ -94,8 +92,7 @@ Layout::relative(char *buf, size_t bufsz, const char *file) size_t path_len = strlen(path) + 1; if (path_len > bufsz) { ink_error("Provided buffer is too small: %zu, required %zu\n", bufsz, path_len); - } - else { + } else { ink_strlcpy(buf, path, bufsz); } } @@ -128,8 +125,7 @@ Layout::relative_to(char *buf, size_t bufsz, const char *dir, const char *file) ink_error("Cannot merge path '%s' above the root '%s'\n", file, dir); } else if (err == E2BIG) { ink_error("Exceeding file name length limit of %d characters\n", PATH_NAME_MAX); - } - else { + } else { // TODO: Make some pretty errors. ink_error("Cannot merge '%s' with '%s' error=%d\n", file, dir, err); } @@ -138,8 +134,7 @@ Layout::relative_to(char *buf, size_t bufsz, const char *dir, const char *file) size_t path_len = strlen(path) + 1; if (path_len > bufsz) { ink_error("Provided buffer is too small: %zu, required %zu\n", bufsz, path_len); - } - else { + } else { ink_strlcpy(buf, path, bufsz); } } @@ -151,12 +146,12 @@ Layout::Layout(const char *_prefix) } else { char *env_path; char path[PATH_NAME_MAX]; - int len; + int len; if ((env_path = getenv("TS_ROOT"))) { len = strlen(env_path); if ((len + 1) > PATH_NAME_MAX) { - ink_error("TS_ROOT environment variable is too big: %d, max %d\n", len, PATH_NAME_MAX -1); + ink_error("TS_ROOT environment variable is too big: %d, max %d\n", len, PATH_NAME_MAX - 1); return; } ink_strlcpy(path, env_path, sizeof(path)); @@ -165,7 +160,7 @@ Layout::Layout(const char *_prefix) --len; } } else { - // Use compile time --prefix + // Use compile time --prefix ink_strlcpy(path, TS_BUILD_PREFIX, sizeof(path)); } @@ -185,7 +180,6 @@ Layout::Layout(const char *_prefix) mandir = layout_relative(prefix, TS_BUILD_MANDIR); infodir = layout_relative(prefix, TS_BUILD_INFODIR); cachedir = layout_relative(prefix, TS_BUILD_CACHEDIR); - } Layout::~Layout() @@ -206,4 +200,3 @@ Layout::~Layout() ats_free(infodir); ats_free(cachedir); } - http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/List.h ---------------------------------------------------------------------- diff --git a/lib/ts/List.h b/lib/ts/List.h index f447b15..e96212c 100644 --- a/lib/ts/List.h +++ b/lib/ts/List.h @@ -52,7 +52,7 @@ ****************************************************************************/ #ifndef _List_h_ -#define _List_h_ +#define _List_h_ #include <stdint.h> @@ -63,17 +63,37 @@ // // Link cell for singly-linked list of objects of type C. // -template <class C> class SLink { - public: +template <class C> class SLink +{ +public: C *next; - SLink() : next(NULL) {}; + SLink() : next(NULL){}; }; -#define SLINK(_c,_f) class Link##_##_f : public SLink<_c> { public: \ - static _c *& next_link(_c *c) { return c->_f.next; } \ - static const _c * next_link(const _c *c) { return c->_f.next; } \ - }; SLink<_c> _f -#define SLINKM(_c,_m,_f) class Link##_##_m##_##_f : public SLink<_c> { public: \ - static _c *& next_link(_c *c) { return c->_m._f.next; } \ +#define SLINK(_c, _f) \ + class Link##_##_f : public SLink<_c> \ + { \ + public: \ + static _c *& \ + next_link(_c *c) \ + { \ + return c->_f.next; \ + } \ + static const _c * \ + next_link(const _c *c) \ + { \ + return c->_f.next; \ + } \ + }; \ + SLink<_c> _f +#define SLINKM(_c, _m, _f) \ + class Link##_##_m##_##_f : public SLink<_c> \ + { \ + public: \ + static _c *& \ + next_link(_c *c) \ + { \ + return c->_m._f.next; \ + } \ }; // @@ -83,52 +103,107 @@ template <class C> struct Link : public SLink<C> { C *prev; Link() : prev(NULL) {} }; -#define LINK(_c,_f) class Link##_##_f : public Link<_c> { public: \ - static _c *& next_link(_c *c) { return c->_f.next; } \ - static _c *& prev_link(_c *c) { return c->_f.prev; } \ - static const _c * next_link(const _c *c) { return c->_f.next; } \ - static const _c * prev_link(const _c *c) { return c->_f.prev; } \ - }; Link<_c> _f -#define LINKM(_c,_m,_f) class Link##_##_m##_##_f : public Link<_c> { public: \ - static _c *& next_link(_c *c) { return c->_m._f.next; } \ - static _c *& prev_link(_c *c) { return c->_m._f.prev; } \ +#define LINK(_c, _f) \ + class Link##_##_f : public Link<_c> \ + { \ + public: \ + static _c *& \ + next_link(_c *c) \ + { \ + return c->_f.next; \ + } \ + static _c *& \ + prev_link(_c *c) \ + { \ + return c->_f.prev; \ + } \ + static const _c * \ + next_link(const _c *c) \ + { \ + return c->_f.next; \ + } \ + static const _c * \ + prev_link(const _c *c) \ + { \ + return c->_f.prev; \ + } \ + }; \ + Link<_c> _f +#define LINKM(_c, _m, _f) \ + class Link##_##_m##_##_f : public Link<_c> \ + { \ + public: \ + static _c *& \ + next_link(_c *c) \ + { \ + return c->_m._f.next; \ + } \ + static _c *& \ + prev_link(_c *c) \ + { \ + return c->_m._f.prev; \ + } \ }; -#define LINK_FORWARD_DECLARATION(_c,_f) class Link##_##_c##_##_f : public Link<_c> { public: \ - static _c *& next_link(_c *c); \ - static _c *& prev_link(_c *c); \ +#define LINK_FORWARD_DECLARATION(_c, _f) \ + class Link##_##_c##_##_f : public Link<_c> \ + { \ + public: \ + static _c *&next_link(_c *c); \ + static _c *&prev_link(_c *c); \ }; -#define LINK_DEFINITION(_c,_f) \ - inline _c *& Link##_##_c##_##_f::next_link(_c *c) { return c->_f.next; } \ - inline _c *& Link##_##_c##_##_f::prev_link(_c *c) { return c->_f.prev; } \ +#define LINK_DEFINITION(_c, _f) \ + inline _c *&Link##_##_c##_##_f::next_link(_c *c) { return c->_f.next; } \ + inline _c *&Link##_##_c##_##_f::prev_link(_c *c) { return c->_f.prev; } // // List descriptor for singly-linked list of objects of type C. // -template <class C, class L = typename C::Link_link> class SLL { - public: +template <class C, class L = typename C::Link_link> class SLL +{ +public: C *head; - bool empty() const { return head == NULL; } + bool + empty() const + { + return head == NULL; + } void push(C *e); C *pop(); - void clear() { head = NULL; } - C *& next(C *e) { return L::next_link(e); } - const C * next(const C *e) const { return L::next_link(e); } + void + clear() + { + head = NULL; + } + C *& + next(C *e) + { + return L::next_link(e); + } + const C * + next(const C *e) const + { + return L::next_link(e); + } SLL() : head(NULL) {} SLL(C *c) : head(c) {} }; -#define SList(_c, _f) SLL<_c, _c::Link##_##_f> +#define SList(_c, _f) SLL<_c, _c::Link##_##_f> #define SListM(_c, _m, _ml, _l) SLL<_c, _c::Link##_##_ml##_##_l> #define forl_LL(_c, _p, _l) for (_c *_p = (_l).head; _p; _p = (_l).next(_p)) -template <class C, class L> inline void -SLL<C,L>::push(C *e) { +template <class C, class L> +inline void +SLL<C, L>::push(C *e) +{ next(e) = head; head = e; } -template <class C, class L> inline C * -SLL<C,L>::pop() { +template <class C, class L> +inline C * +SLL<C, L>::pop() +{ C *ret = head; if (ret) { head = next(ret); @@ -142,43 +217,81 @@ SLL<C,L>::pop() { // template <class C, class L = typename C::Link_link> struct DLL { C *head; - bool empty() const { return head == NULL; } + bool + empty() const + { + return head == NULL; + } void push(C *e); C *pop(); void remove(C *e); void insert(C *e, C *after); - bool in(C *e) { return head == e || next(e) || prev(e); } - void clear() { head = NULL; } - static C *&next(C *e) { return reinterpret_cast<C*&>(L::next_link(e)); } - static C *&prev(C *e) { return reinterpret_cast<C*&>(L::prev_link(e)); } - static C const* next(const C *e) { return L::next_link(e); } - static C const* prev(const C *e) { return L::prev_link(e); } + bool + in(C *e) + { + return head == e || next(e) || prev(e); + } + void + clear() + { + head = NULL; + } + static C *& + next(C *e) + { + return reinterpret_cast<C *&>(L::next_link(e)); + } + static C *& + prev(C *e) + { + return reinterpret_cast<C *&>(L::prev_link(e)); + } + static C const * + next(const C *e) + { + return L::next_link(e); + } + static C const * + prev(const C *e) + { + return L::prev_link(e); + } DLL() : head(NULL) {} }; -#define DList(_c, _f) DLL<_c, _c::Link##_##_f> +#define DList(_c, _f) DLL<_c, _c::Link##_##_f> #define DListM(_c, _m, _ml, _l) DLL<_c, _c::Link##_##_ml##_##_l> -template <class C, class L> inline void -DLL<C,L>::push(C *e) { +template <class C, class L> +inline void +DLL<C, L>::push(C *e) +{ if (head) prev(head) = e; next(e) = head; head = e; } -template <class C, class L> inline void -DLL<C,L>::remove(C *e) { - if (!head) return; - if (e == head) head = next(e); - if (prev(e)) next(prev(e)) = next(e); - if (next(e)) prev(next(e)) = prev(e); +template <class C, class L> +inline void +DLL<C, L>::remove(C *e) +{ + if (!head) + return; + if (e == head) + head = next(e); + if (prev(e)) + next(prev(e)) = next(e); + if (next(e)) + prev(next(e)) = prev(e); prev(e) = NULL; next(e) = NULL; } -template <class C, class L> inline C * -DLL<C,L>::pop() { +template <class C, class L> +inline C * +DLL<C, L>::pop() +{ C *ret = head; if (ret) { head = next(ret); @@ -190,21 +303,28 @@ DLL<C,L>::pop() { return NULL; } -template <class C, class L> inline void -DLL<C,L>::insert(C *e, C *after) { - if (!after) { push(e); return; } +template <class C, class L> +inline void +DLL<C, L>::insert(C *e, C *after) +{ + if (!after) { + push(e); + return; + } prev(e) = after; next(e) = next(after); next(after) = e; - if (next(e)) prev(next(e)) = e; + if (next(e)) + prev(next(e)) = e; } // // List descriptor for queue of objects of type C. // -template <class C, class L = typename C::Link_link> class Queue : public DLL<C,L> { - public: - using DLL<C,L>::head; +template <class C, class L = typename C::Link_link> class Queue : public DLL<C, L> +{ +public: + using DLL<C, L>::head; C *tail; void push(C *e); C *pop(); @@ -213,47 +333,68 @@ template <class C, class L = typename C::Link_link> class Queue : public DLL<C,L C *dequeue(); void remove(C *e); void insert(C *e, C *after); - void append(Queue<C,L> q); - void append(DLL<C,L> q); - void clear() { head = NULL; tail = NULL; } - bool empty() const { return head == NULL; } + void append(Queue<C, L> q); + void append(DLL<C, L> q); + void + clear() + { + head = NULL; + tail = NULL; + } + bool + empty() const + { + return head == NULL; + } Queue() : tail(NULL) {} }; #define Que(_c, _f) Queue<_c, _c::Link##_##_f> #define QueM(_c, _m, _mf, _f) Queue<_c, _c::Link##_##_mf##_##_f> -template <class C, class L> inline void -Queue<C,L>::push(C *e) { - DLL<C,L>::push(e); - if (!tail) tail = head; +template <class C, class L> +inline void +Queue<C, L>::push(C *e) +{ + DLL<C, L>::push(e); + if (!tail) + tail = head; } -template <class C, class L> inline C * -Queue<C,L>::pop() { - C *ret = DLL<C,L>::pop(); - if (!head) tail = NULL; +template <class C, class L> +inline C * +Queue<C, L>::pop() +{ + C *ret = DLL<C, L>::pop(); + if (!head) + tail = NULL; return ret; } -template <class C, class L> inline void -Queue<C,L>::insert(C *e, C *after) { - DLL<C,L>::insert(e, after); +template <class C, class L> +inline void +Queue<C, L>::insert(C *e, C *after) +{ + DLL<C, L>::insert(e, after); if (!tail) tail = head; else if (tail == after) tail = e; } -template <class C, class L> inline void -Queue<C,L>::remove(C *e) { +template <class C, class L> +inline void +Queue<C, L>::remove(C *e) +{ if (tail == e) - tail = (C*)this->prev(e); - DLL<C,L>::remove(e); + tail = (C *)this->prev(e); + DLL<C, L>::remove(e); } -template <class C, class L> inline void -Queue<C,L>::append(DLL<C,L> q) { +template <class C, class L> +inline void +Queue<C, L>::append(DLL<C, L> q) +{ C *qtail = q.head; if (qtail) while (this->next(qtail)) @@ -270,8 +411,10 @@ Queue<C,L>::append(DLL<C,L> q) { } } -template <class C, class L> inline void -Queue<C,L>::append(Queue<C,L> q) { +template <class C, class L> +inline void +Queue<C, L>::append(Queue<C, L> q) +{ if (!head) { head = q.head; tail = q.tail; @@ -284,21 +427,28 @@ Queue<C,L>::append(Queue<C,L> q) { } } -template <class C, class L> inline void -Queue<C,L>::enqueue(C *e) { +template <class C, class L> +inline void +Queue<C, L>::enqueue(C *e) +{ if (tail) insert(e, tail); else push(e); } -template <class C, class L> inline void -Queue<C,L>::in_or_enqueue(C *e) { - if (!this->in(e)) enqueue(e); +template <class C, class L> +inline void +Queue<C, L>::in_or_enqueue(C *e) +{ + if (!this->in(e)) + enqueue(e); } -template <class C, class L> inline C * -Queue<C,L>::dequeue() { +template <class C, class L> +inline C * +Queue<C, L>::dequeue() +{ return pop(); } @@ -306,12 +456,14 @@ Queue<C,L>::dequeue() { // Adds sorting, but requires that elements implement < // -template<class C, class L = typename C::Link_link> struct SortableQueue: public Queue<C,L> -{ - using DLL<C,L>::head; - using Queue<C,L>::tail; - void sort() { - if (!head) return; +template <class C, class L = typename C::Link_link> struct SortableQueue : public Queue<C, L> { + using DLL<C, L>::head; + using Queue<C, L>::tail; + void + sort() + { + if (!head) + return; bool clean = false; while (!clean) { clean = true; @@ -355,7 +507,7 @@ template<class C, class L = typename C::Link_link> struct SortableQueue: public // Adds counting to the Queue // -template <class C, class L = typename C::Link_link> struct CountQueue : public Queue<C,L> { +template <class C, class L = typename C::Link_link> struct CountQueue : public Queue<C, L> { int size; inline CountQueue(void) : size(0) {} inline void push(C *e); @@ -364,57 +516,73 @@ template <class C, class L = typename C::Link_link> struct CountQueue : public Q inline C *dequeue(); inline void remove(C *e); inline void insert(C *e, C *after); - inline void append(CountQueue<C,L> &q); - inline void append_clear(CountQueue<C,L> &q); + inline void append(CountQueue<C, L> &q); + inline void append_clear(CountQueue<C, L> &q); }; #define CountQue(_c, _f) CountQueue<_c, _c::Link##_##_f> #define CountQueM(_c, _m, _mf, _f) CountQueue<_c, _c::Link##_##_mf##_##_f> -template <class C, class L> inline void -CountQueue<C,L>::push(C *e) { - Queue<C,L>::push(e); +template <class C, class L> +inline void +CountQueue<C, L>::push(C *e) +{ + Queue<C, L>::push(e); size++; } -template <class C, class L> inline C * -CountQueue<C,L>::pop() { - C *ret = Queue<C,L>::pop(); +template <class C, class L> +inline C * +CountQueue<C, L>::pop() +{ + C *ret = Queue<C, L>::pop(); if (ret) size--; return ret; } -template <class C, class L> inline void -CountQueue<C,L>::remove(C *e) { - Queue<C,L>::remove(e); +template <class C, class L> +inline void +CountQueue<C, L>::remove(C *e) +{ + Queue<C, L>::remove(e); size--; } -template <class C, class L> inline void -CountQueue<C,L>::enqueue(C *e) { - Queue<C,L>::enqueue(e); +template <class C, class L> +inline void +CountQueue<C, L>::enqueue(C *e) +{ + Queue<C, L>::enqueue(e); size++; } -template <class C, class L> inline C * -CountQueue<C,L>::dequeue() { +template <class C, class L> +inline C * +CountQueue<C, L>::dequeue() +{ return pop(); } -template <class C, class L> inline void -CountQueue<C,L>::insert(C *e, C *after) { - Queue<C,L>::insert(e, after); +template <class C, class L> +inline void +CountQueue<C, L>::insert(C *e, C *after) +{ + Queue<C, L>::insert(e, after); size++; } -template <class C, class L> inline void -CountQueue<C,L>::append(CountQueue<C,L> &q) { - Queue<C,L>::append(q); +template <class C, class L> +inline void +CountQueue<C, L>::append(CountQueue<C, L> &q) +{ + Queue<C, L>::append(q); size += q.size; } -template <class C, class L> inline void -CountQueue<C,L>::append_clear(CountQueue<C,L> &q) { +template <class C, class L> +inline void +CountQueue<C, L>::append_clear(CountQueue<C, L> &q) +{ append(q); q.head = q.tail = 0; q.size = 0; @@ -424,10 +592,9 @@ CountQueue<C,L>::append_clear(CountQueue<C,L> &q) { // List using cons cells // -template <class C, class A = DefaultAlloc> -struct ConsCell { - C car; - ConsCell *cdr; +template <class C, class A = DefaultAlloc> struct ConsCell { + C car; + ConsCell *cdr; ConsCell(C acar, ConsCell *acdr) : car(acar), cdr(acdr) {} ConsCell(C acar) : car(acar), cdr(NULL) {} ConsCell(ConsCell *acdr) : cdr(acdr) {} @@ -435,29 +602,72 @@ struct ConsCell { static void operator delete(void *p, size_t /* size ATS_UNUSED */) { A::free(p); } }; -template <class C, class A = DefaultAlloc> -struct List { - ConsCell<C,A> *head; - C first() { if (head) return head->car; else return 0; } - C car() { return first(); } - ConsCell<C,A> *rest() { if (head) return head->cdr; else return 0; } - ConsCell<C,A> *cdr() { return rest(); } - void push(C a) { head = new ConsCell<C,A>(a, head); } - void push() { head = new ConsCell<C,A>(head); } - C pop() { C a = car(); head = cdr(); return a; } - void clear() { head = NULL; } +template <class C, class A = DefaultAlloc> struct List { + ConsCell<C, A> *head; + C + first() + { + if (head) + return head->car; + else + return 0; + } + C + car() + { + return first(); + } + ConsCell<C, A> * + rest() + { + if (head) + return head->cdr; + else + return 0; + } + ConsCell<C, A> * + cdr() + { + return rest(); + } + void + push(C a) + { + head = new ConsCell<C, A>(a, head); + } + void + push() + { + head = new ConsCell<C, A>(head); + } + C + pop() + { + C a = car(); + head = cdr(); + return a; + } + void + clear() + { + head = NULL; + } void reverse(); - List(C acar) : head(new ConsCell<C,A>(acar)) {} - List(C a, C b) : head(new ConsCell<C,A>(a, new ConsCell<C,A>(b))) {} - List(C a, C b, C c) : head(new ConsCell<C,A>(a, new ConsCell<C,A>(b, new ConsCell<C,A>(c)))) {} + List(C acar) : head(new ConsCell<C, A>(acar)) {} + List(C a, C b) : head(new ConsCell<C, A>(a, new ConsCell<C, A>(b))) {} + List(C a, C b, C c) : head(new ConsCell<C, A>(a, new ConsCell<C, A>(b, new ConsCell<C, A>(c)))) {} List() : head(0) {} }; -#define forc_List(_c, _p, _l) if ((_l).head) for (_c *_p = (_l).head; _p; _p = _p->cdr) +#define forc_List(_c, _p, _l) \ + if ((_l).head) \ + for (_c *_p = (_l).head; _p; _p = _p->cdr) -template <class C,class A> void -List<C,A>::reverse() { - ConsCell<C,A> *n, *t; - for (ConsCell<C,A> *p = head; p; p = n) { +template <class C, class A> +void +List<C, A>::reverse() +{ + ConsCell<C, A> *n, *t; + for (ConsCell<C, A> *p = head; p; p = n) { n = p->cdr; p->cdr = t; t = p; @@ -469,12 +679,27 @@ List<C,A>::reverse() { // Atomic lists // -template<class C, class L = typename C::Link_link> struct AtomicSLL -{ - void push(C * c) { ink_atomiclist_push(&al, c); } - C *pop() { return (C *) ink_atomiclist_pop(&al); } - C *popall() { return (C *) ink_atomiclist_popall(&al); } - bool empty() { return INK_ATOMICLIST_EMPTY(al); } +template <class C, class L = typename C::Link_link> struct AtomicSLL { + void + push(C *c) + { + ink_atomiclist_push(&al, c); + } + C * + pop() + { + return (C *)ink_atomiclist_pop(&al); + } + C * + popall() + { + return (C *)ink_atomiclist_popall(&al); + } + bool + empty() + { + return INK_ATOMICLIST_EMPTY(al); + } /* * WARNING WARNING WARNING WARNING WARNING WARNING WARNING @@ -482,9 +707,21 @@ template<class C, class L = typename C::Link_link> struct AtomicSLL * which only that thread can use as well. * WARNING WARNING WARNING WARNING WARNING WARNING WARNING */ - C *remove(C * c) { return (C *) ink_atomiclist_remove(&al, c); } - C *head() { return (C *) TO_PTR(FREELIST_POINTER(al.head)); } - C *next(C * c) { return (C *) TO_PTR(c); } + C * + remove(C *c) + { + return (C *)ink_atomiclist_remove(&al, c); + } + C * + head() + { + return (C *)TO_PTR(FREELIST_POINTER(al.head)); + } + C * + next(C *c) + { + return (C *)TO_PTR(c); + } InkAtomicList al; @@ -494,8 +731,9 @@ template<class C, class L = typename C::Link_link> struct AtomicSLL #define ASLL(_c, _l) AtomicSLL<_c, _c::Link##_##_l> #define ASLLM(_c, _m, _ml, _l) AtomicSLL<_c, _c::Link##_##_ml##_##_l> -template<class C, class L> inline AtomicSLL<C,L>::AtomicSLL() { - ink_atomiclist_init(&al, "AtomicSLL", (uint32_t)(uintptr_t)&L::next_link((C*)0)); +template <class C, class L> inline AtomicSLL<C, L>::AtomicSLL() +{ + ink_atomiclist_init(&al, "AtomicSLL", (uint32_t)(uintptr_t)&L::next_link((C *)0)); } -#endif /*_List_h_*/ +#endif /*_List_h_*/ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/MMH.cc ---------------------------------------------------------------------- diff --git a/lib/ts/MMH.cc b/lib/ts/MMH.cc index 66d5c48..4154aee 100644 --- a/lib/ts/MMH.cc +++ b/lib/ts/MMH.cc @@ -27,141 +27,62 @@ #include "ink_platform.h" #include "MMH.h" -#define MMH_X_SIZE 512 +#define MMH_X_SIZE 512 /* BUG: INKqa11504: need it be to 64 bits...otherwise it overflows */ static uint64_t MMH_x[MMH_X_SIZE + 8] = { - 0x3ee18b32, 0x746d0d6b, 0x591be6a3, 0x760bd17f, - 0x363c765d, 0x4bf3d5c5, 0x10f0510a, 0x39a84605, - 0x2282b48f, 0x6903652e, 0x1b491170, 0x1ab8407a, - 0x776b8aa8, 0x5b126ffe, 0x5095db1a, 0x565fe90c, - 0x3ae1f068, 0x73fdf0cb, 0x72f39a81, 0x6a40a4a3, - 0x4ef557fe, 0x360c1a2c, 0x4579b0ea, 0x61dfd174, - 0x269b242f, 0x752d6298, 0x15f10fa3, 0x618b7ab3, - 0x6699171f, 0x488f2c6c, 0x790f8cdb, 0x5ed15565, - 0x04eba3c0, 0x5009ac0b, 0x3a5d6c1f, 0x1a4f7853, - 0x1affabd4, 0x74aace1f, 0x2310b46d, 0x466b611a, - 0x18c5d4a0, 0x7eb9fffe, 0x76098df6, 0x4172f860, - 0x689e3c2f, 0x722cdc29, 0x64548175, 0x28f46721, - 0x58fdf93f, 0x12c2dcee, 0x58cb1327, 0x02d4af27, - 0x4d1c6fcd, 0x72fe572d, 0x7038d366, 0x0bfa1898, - 0x788d2438, 0x1f131f37, 0x25729ee6, 0x635ea6a9, - 0x3b0b5714, 0x6ac759d2, 0x5faf688a, 0x0c2fe571, - 0x7487538e, 0x65491b59, 0x60cd86e4, 0x5d6482d8, - 0x4a59fa77, 0x78439700, 0x56a51f48, 0x360544ae, - 0x6c01b3ef, 0x2228c036, 0x15b7e88b, 0x326e0dd8, - 0x509491af, 0x72d06023, 0x26181f5d, 0x7924c4a4, - 0x70c60bf2, 0x7b5bc151, 0x28e42640, 0x48af0c3e, - 0x009b6301, 0x06dd3366, 0x2ad1eb24, 0x102ce33c, - 0x1e504f5a, 0x5ab4c90f, 0x669ccca1, 0x118d5954, - 0x1a1e4a7c, 0x1807d1f9, 0x525a58d0, 0x2f13ae2d, - 0x17335a52, 0x714eb2f9, 0x1865dfc7, 0x61b64b52, - 0x0dc9e939, 0x4fccde4c, 0x6d5873af, 0x47c62b43, - 0x0fa1d4b0, 0x2f00cdf8, 0x68029083, 0x52645fa6, - 0x4bb37c9b, 0x53d60251, 0x48364566, 0x35b4889b, - 0x46783d34, 0x30c12697, 0x210459a1, 0x36962f2d, - 0x36305d8f, 0x170e9dbd, 0x687c8739, 0x261c14e4, - 0x3cc51cc7, 0x02add945, 0x01a88529, 0x6617aa77, - 0x6be627ca, 0x14c7fc46, 0x46fb3b41, 0x1bffff9e, - 0x1e6c61be, 0x10966c8f, 0x3f69199b, 0x1b5e9e06, - 0x4880890f, 0x055613e6, 0x6c742db5, 0x7be1e15e, - 0x2522e317, 0x41fe3369, 0x2b462f30, 0x605b7e8e, - 0x1c19b868, 0x3fadcb16, 0x781c5e24, 0x1c6b0c08, - 0x499f0bb9, 0x04b0b766, 0x7d6cad1e, 0x097f7d36, - 0x2e02956a, 0x03adc713, 0x4ce950b7, 0x6e57a313, - 0x557badb5, 0x73212afb, 0x3f7f6ed2, 0x0558e3d6, - 0x28376f73, 0x54dac21d, 0x6c3f4771, 0x67147bc8, - 0x5ae9fd88, 0x51ede3c0, 0x1067d134, 0x5246b937, - 0x056e74ed, 0x5d7869b2, 0x62356370, 0x76a0c583, - 0x3defb558, 0x5200dcae, 0x1432a7e8, 0x3ae4ad55, - 0x0c4cca8a, 0x0607c4d7, 0x1944ae2b, 0x726479f0, - 0x558e6035, 0x5ae64061, 0x4e1e9a8a, 0x0cf04d9f, - 0x46ef4a87, 0x0554224f, 0x70d70ab3, 0x03cc954e, - 0x39d0cd57, 0x1b11fb56, 0x62a0e9ee, 0x55888135, - 0x3e93ebeb, 0x29578ee1, 0x0bcb0ef4, 0x529e16af, - 0x165bab64, 0x39ed562e, 0x52c59d67, 0x48c84d29, - 0x0fd0d1c7, 0x795fd395, 0x79a1c4f3, 0x5010c835, - 0x4fbe4ba8, 0x49a597e9, 0x29f017ff, 0x59dde0be, - 0x2c660275, 0x15fcfbf7, 0x1eab540f, 0x38e2cf56, - 0x74608d5c, 0x7cd4b02c, 0x52a115b9, 0x2bdee9ac, - 0x5456c6da, 0x63626453, 0x15279241, 0x19b60519, - 0x508af0e1, 0x2e3ce97b, 0x568710d4, 0x6abb3059, - 0x7897b1a5, 0x17034ff6, 0x2aef7d5e, 0x5a281657, - 0x0fa5d304, 0x76f0a37e, 0x31be0f08, 0x46ce7c20, - 0x563e4e90, 0x31540773, 0x1cdc9c51, 0x10366bfa, - 0x1b6cd03a, 0x615f1540, 0x18c3d6c8, 0x3cb2bf8e, - 0x29bf799c, 0x40b87edb, 0x42c34863, 0x1e9edb40, - 0x64734fe2, 0x3ddf176a, 0x1c458c7f, 0x06138c9f, - 0x5e695e56, 0x02c98403, 0x0474de75, 0x660e1df8, - 0x6df73788, 0x3770f68c, 0x758bb7d5, 0x0763d105, - 0x16e61f16, 0x153974c1, 0x29ded842, 0x1a0d12c3, - 0x599ec61d, 0x05904d54, 0x79e9b0ea, 0x4976da61, - 0x5834243c, 0x67c17d2f, 0x65fbcda0, 0x17bdc554, - 0x465e9741, 0x7a0ee6d5, 0x3b357597, 0x0d1da287, - 0x01211373, 0x04a05de6, 0x5deb5dbd, 0x6d993eb0, - 0x2064ce7c, 0x3011a8c1, 0x36ece6b1, 0x4a0963be, - 0x0cf46ef0, 0x0d53ba44, 0x63260063, 0x187f1d6e, - 0x7e866a7e, 0x4b6885af, 0x254d6d47, 0x715474fd, - 0x6896dcb2, 0x7554eea6, 0x2161bf36, 0x5387f5f8, - 0x5c4bc064, 0x059a7755, 0x7d4307e1, 0x17326e2f, - 0x5e2315c1, 0x14c26eae, 0x1e5cd6f2, 0x352b7ac8, - 0x66591ef3, 0x381e80cd, 0x19b3bfc1, 0x3668946f, - 0x4b6d7d70, 0x20feab7d, 0x1b6340af, 0x356b6cab, - 0x299099dc, 0x295ab8d4, 0x184c8623, 0x134f8e4c, - 0x7caf609c, 0x716d81f9, 0x2e04231f, 0x1dd45301, - 0x43e9fcf9, 0x1c225c06, 0x0994797e, 0x5b3f6006, - 0x1d22dcec, 0x32993108, 0x3f0c2bcc, 0x4d44fbfa, - 0x389de78c, 0x7f8be723, 0x5dab92c1, 0x7866afce, - 0x3bfc7011, 0x4a27d7d3, 0x0c79d05c, 0x268dc4da, - 0x3fe10f84, 0x1f18394d, 0x20b9ba99, 0x312e520a, - 0x64cf2f05, 0x322a7c04, 0x4cc077ce, 0x7218aa35, - 0x550cacb8, 0x5943be47, 0x15b346a8, 0x0d6a1d8e, - 0x3f08a54d, 0x7a6e9807, 0x274f8bbc, 0x6feb2033, - 0x64b10c2b, 0x2cbaa0b7, 0x0db7decc, 0x22b807e3, - 0x10d15c39, 0x6a9b314c, 0x5ff27199, 0x5072b2cd, - 0x4eaf4b49, 0x5a890464, 0x7df0ca60, 0x548e8983, - 0x5e3f0a21, 0x70027683, 0x503e6bf2, 0x47ad6e0d, - 0x77173b26, 0x6dc04878, 0x4d73a573, 0x439b4a1a, - 0x2e6569a7, 0x1630e5de, 0x1be363af, 0x6f5f0e52, - 0x5b266bc3, 0x2f2a51be, 0x204e7e14, 0x1b3314c6, - 0x4472b8f9, 0x4162fb52, 0x72549950, 0x3223f889, - 0x0e655f4a, 0x65c3dce4, 0x04825988, 0x22b41458, - 0x53a4e10d, 0x3e2a66d5, 0x29de3e31, 0x0252fa74, - 0x267fe54f, 0x42d6d8ba, 0x5951218f, 0x73db5791, - 0x618444e4, 0x79abcaa1, 0x0ddcf5c8, 0x2cbed2e6, - 0x73159e0e, 0x7aadc871, 0x10e3f9a4, 0x762e9d65, - 0x2a7138c9, 0x59fe016f, 0x5b6c3ee4, 0x28888205, - 0x695fa5b1, 0x50f92ddd, 0x07eefc3b, 0x42bb693a, - 0x71312191, 0x3653ecbd, 0x1d80c4ed, 0x5a536187, - 0x6a286789, 0x4a1ffbb3, 0x1e976003, 0x5a8c5f29, - 0x2ac83bdb, 0x5ab9cb08, 0x63039928, 0x5a4c04f4, - 0x7b329952, 0x40d40fcb, 0x01810524, 0x2555e83c, - 0x748d0b4f, 0x534f1612, 0x272353f2, 0x6992e1ea, - 0x33cc5e71, 0x5163b55e, 0x29886a7f, 0x7cfb1eae, - 0x330271e0, 0x6f05e91c, 0x35b01e02, 0x64bbc053, - 0x76eb9337, 0x62612f48, 0x044e0af2, 0x1dac022e, - 0x1ca56f0c, 0x0210ef2c, 0x5af7a1a9, 0x2632f2b0, - 0x23d0401c, 0x0c594a46, 0x77582293, 0x297df41b, - 0x4c7b8718, 0x6c48d948, 0x4835e412, 0x74795651, - 0x28ca3506, 0x4071f739, 0x032fdbf2, 0x097f7bc8, - 0x44ced256, 0x47f25cb9, 0x43500684, 0x45481b9a, - 0x5a5ecc82, 0x4fe9ed61, 0x337ee559, 0x556852b9, - 0x0b24b460, 0x696db949, 0x7a2def9d, 0x4fcd5640, - 0x1babd707, 0x5c9254a3, 0x44d26e0d, 0x0e26b8e4, - 0x3b1c3b5c, 0x0078c784, 0x27a7dc96, 0x1d525589, - 0x4384ae38, 0x447b77c3, 0x78488b8c, 0x5eab10f1, - 0x16812737, 0x37cc8efa, 0x219cda83, 0x00bcc48f, - 0x3c667020, 0x492d7eaa, 0x710d06ce, 0x4172c47a, - 0x358098ec, 0x1fff647b, 0x65672792, 0x1a7b927d, - 0x24006275, 0x04e630a0, 0x2f2a9185, 0x5873704b, - 0x0a8c69bc, 0x06b49059, 0x49837c48, 0x4f90a2d0, - 0x29ad7dd7, 0x3674be92, 0x46d5635f, 0x782758a2, - 0x721a2a75, 0x13427ca9, 0x20e03cc9, 0x5f884596, - 0x19dc210f, 0x066c954d, 0x52f43f40, 0x5d9c256f, - 0x7f0acaae, 0x1e186b81, 0x55e9920f, 0x0e4f77b2, - 0x6700ec53, 0x268837c0, 0x554ce08b, 0x4284e695, - 0x2127e806, 0x384cb53b, 0x51076b2f, 0x23f9eb15 -}; + 0x3ee18b32, 0x746d0d6b, 0x591be6a3, 0x760bd17f, 0x363c765d, 0x4bf3d5c5, 0x10f0510a, 0x39a84605, 0x2282b48f, 0x6903652e, + 0x1b491170, 0x1ab8407a, 0x776b8aa8, 0x5b126ffe, 0x5095db1a, 0x565fe90c, 0x3ae1f068, 0x73fdf0cb, 0x72f39a81, 0x6a40a4a3, + 0x4ef557fe, 0x360c1a2c, 0x4579b0ea, 0x61dfd174, 0x269b242f, 0x752d6298, 0x15f10fa3, 0x618b7ab3, 0x6699171f, 0x488f2c6c, + 0x790f8cdb, 0x5ed15565, 0x04eba3c0, 0x5009ac0b, 0x3a5d6c1f, 0x1a4f7853, 0x1affabd4, 0x74aace1f, 0x2310b46d, 0x466b611a, + 0x18c5d4a0, 0x7eb9fffe, 0x76098df6, 0x4172f860, 0x689e3c2f, 0x722cdc29, 0x64548175, 0x28f46721, 0x58fdf93f, 0x12c2dcee, + 0x58cb1327, 0x02d4af27, 0x4d1c6fcd, 0x72fe572d, 0x7038d366, 0x0bfa1898, 0x788d2438, 0x1f131f37, 0x25729ee6, 0x635ea6a9, + 0x3b0b5714, 0x6ac759d2, 0x5faf688a, 0x0c2fe571, 0x7487538e, 0x65491b59, 0x60cd86e4, 0x5d6482d8, 0x4a59fa77, 0x78439700, + 0x56a51f48, 0x360544ae, 0x6c01b3ef, 0x2228c036, 0x15b7e88b, 0x326e0dd8, 0x509491af, 0x72d06023, 0x26181f5d, 0x7924c4a4, + 0x70c60bf2, 0x7b5bc151, 0x28e42640, 0x48af0c3e, 0x009b6301, 0x06dd3366, 0x2ad1eb24, 0x102ce33c, 0x1e504f5a, 0x5ab4c90f, + 0x669ccca1, 0x118d5954, 0x1a1e4a7c, 0x1807d1f9, 0x525a58d0, 0x2f13ae2d, 0x17335a52, 0x714eb2f9, 0x1865dfc7, 0x61b64b52, + 0x0dc9e939, 0x4fccde4c, 0x6d5873af, 0x47c62b43, 0x0fa1d4b0, 0x2f00cdf8, 0x68029083, 0x52645fa6, 0x4bb37c9b, 0x53d60251, + 0x48364566, 0x35b4889b, 0x46783d34, 0x30c12697, 0x210459a1, 0x36962f2d, 0x36305d8f, 0x170e9dbd, 0x687c8739, 0x261c14e4, + 0x3cc51cc7, 0x02add945, 0x01a88529, 0x6617aa77, 0x6be627ca, 0x14c7fc46, 0x46fb3b41, 0x1bffff9e, 0x1e6c61be, 0x10966c8f, + 0x3f69199b, 0x1b5e9e06, 0x4880890f, 0x055613e6, 0x6c742db5, 0x7be1e15e, 0x2522e317, 0x41fe3369, 0x2b462f30, 0x605b7e8e, + 0x1c19b868, 0x3fadcb16, 0x781c5e24, 0x1c6b0c08, 0x499f0bb9, 0x04b0b766, 0x7d6cad1e, 0x097f7d36, 0x2e02956a, 0x03adc713, + 0x4ce950b7, 0x6e57a313, 0x557badb5, 0x73212afb, 0x3f7f6ed2, 0x0558e3d6, 0x28376f73, 0x54dac21d, 0x6c3f4771, 0x67147bc8, + 0x5ae9fd88, 0x51ede3c0, 0x1067d134, 0x5246b937, 0x056e74ed, 0x5d7869b2, 0x62356370, 0x76a0c583, 0x3defb558, 0x5200dcae, + 0x1432a7e8, 0x3ae4ad55, 0x0c4cca8a, 0x0607c4d7, 0x1944ae2b, 0x726479f0, 0x558e6035, 0x5ae64061, 0x4e1e9a8a, 0x0cf04d9f, + 0x46ef4a87, 0x0554224f, 0x70d70ab3, 0x03cc954e, 0x39d0cd57, 0x1b11fb56, 0x62a0e9ee, 0x55888135, 0x3e93ebeb, 0x29578ee1, + 0x0bcb0ef4, 0x529e16af, 0x165bab64, 0x39ed562e, 0x52c59d67, 0x48c84d29, 0x0fd0d1c7, 0x795fd395, 0x79a1c4f3, 0x5010c835, + 0x4fbe4ba8, 0x49a597e9, 0x29f017ff, 0x59dde0be, 0x2c660275, 0x15fcfbf7, 0x1eab540f, 0x38e2cf56, 0x74608d5c, 0x7cd4b02c, + 0x52a115b9, 0x2bdee9ac, 0x5456c6da, 0x63626453, 0x15279241, 0x19b60519, 0x508af0e1, 0x2e3ce97b, 0x568710d4, 0x6abb3059, + 0x7897b1a5, 0x17034ff6, 0x2aef7d5e, 0x5a281657, 0x0fa5d304, 0x76f0a37e, 0x31be0f08, 0x46ce7c20, 0x563e4e90, 0x31540773, + 0x1cdc9c51, 0x10366bfa, 0x1b6cd03a, 0x615f1540, 0x18c3d6c8, 0x3cb2bf8e, 0x29bf799c, 0x40b87edb, 0x42c34863, 0x1e9edb40, + 0x64734fe2, 0x3ddf176a, 0x1c458c7f, 0x06138c9f, 0x5e695e56, 0x02c98403, 0x0474de75, 0x660e1df8, 0x6df73788, 0x3770f68c, + 0x758bb7d5, 0x0763d105, 0x16e61f16, 0x153974c1, 0x29ded842, 0x1a0d12c3, 0x599ec61d, 0x05904d54, 0x79e9b0ea, 0x4976da61, + 0x5834243c, 0x67c17d2f, 0x65fbcda0, 0x17bdc554, 0x465e9741, 0x7a0ee6d5, 0x3b357597, 0x0d1da287, 0x01211373, 0x04a05de6, + 0x5deb5dbd, 0x6d993eb0, 0x2064ce7c, 0x3011a8c1, 0x36ece6b1, 0x4a0963be, 0x0cf46ef0, 0x0d53ba44, 0x63260063, 0x187f1d6e, + 0x7e866a7e, 0x4b6885af, 0x254d6d47, 0x715474fd, 0x6896dcb2, 0x7554eea6, 0x2161bf36, 0x5387f5f8, 0x5c4bc064, 0x059a7755, + 0x7d4307e1, 0x17326e2f, 0x5e2315c1, 0x14c26eae, 0x1e5cd6f2, 0x352b7ac8, 0x66591ef3, 0x381e80cd, 0x19b3bfc1, 0x3668946f, + 0x4b6d7d70, 0x20feab7d, 0x1b6340af, 0x356b6cab, 0x299099dc, 0x295ab8d4, 0x184c8623, 0x134f8e4c, 0x7caf609c, 0x716d81f9, + 0x2e04231f, 0x1dd45301, 0x43e9fcf9, 0x1c225c06, 0x0994797e, 0x5b3f6006, 0x1d22dcec, 0x32993108, 0x3f0c2bcc, 0x4d44fbfa, + 0x389de78c, 0x7f8be723, 0x5dab92c1, 0x7866afce, 0x3bfc7011, 0x4a27d7d3, 0x0c79d05c, 0x268dc4da, 0x3fe10f84, 0x1f18394d, + 0x20b9ba99, 0x312e520a, 0x64cf2f05, 0x322a7c04, 0x4cc077ce, 0x7218aa35, 0x550cacb8, 0x5943be47, 0x15b346a8, 0x0d6a1d8e, + 0x3f08a54d, 0x7a6e9807, 0x274f8bbc, 0x6feb2033, 0x64b10c2b, 0x2cbaa0b7, 0x0db7decc, 0x22b807e3, 0x10d15c39, 0x6a9b314c, + 0x5ff27199, 0x5072b2cd, 0x4eaf4b49, 0x5a890464, 0x7df0ca60, 0x548e8983, 0x5e3f0a21, 0x70027683, 0x503e6bf2, 0x47ad6e0d, + 0x77173b26, 0x6dc04878, 0x4d73a573, 0x439b4a1a, 0x2e6569a7, 0x1630e5de, 0x1be363af, 0x6f5f0e52, 0x5b266bc3, 0x2f2a51be, + 0x204e7e14, 0x1b3314c6, 0x4472b8f9, 0x4162fb52, 0x72549950, 0x3223f889, 0x0e655f4a, 0x65c3dce4, 0x04825988, 0x22b41458, + 0x53a4e10d, 0x3e2a66d5, 0x29de3e31, 0x0252fa74, 0x267fe54f, 0x42d6d8ba, 0x5951218f, 0x73db5791, 0x618444e4, 0x79abcaa1, + 0x0ddcf5c8, 0x2cbed2e6, 0x73159e0e, 0x7aadc871, 0x10e3f9a4, 0x762e9d65, 0x2a7138c9, 0x59fe016f, 0x5b6c3ee4, 0x28888205, + 0x695fa5b1, 0x50f92ddd, 0x07eefc3b, 0x42bb693a, 0x71312191, 0x3653ecbd, 0x1d80c4ed, 0x5a536187, 0x6a286789, 0x4a1ffbb3, + 0x1e976003, 0x5a8c5f29, 0x2ac83bdb, 0x5ab9cb08, 0x63039928, 0x5a4c04f4, 0x7b329952, 0x40d40fcb, 0x01810524, 0x2555e83c, + 0x748d0b4f, 0x534f1612, 0x272353f2, 0x6992e1ea, 0x33cc5e71, 0x5163b55e, 0x29886a7f, 0x7cfb1eae, 0x330271e0, 0x6f05e91c, + 0x35b01e02, 0x64bbc053, 0x76eb9337, 0x62612f48, 0x044e0af2, 0x1dac022e, 0x1ca56f0c, 0x0210ef2c, 0x5af7a1a9, 0x2632f2b0, + 0x23d0401c, 0x0c594a46, 0x77582293, 0x297df41b, 0x4c7b8718, 0x6c48d948, 0x4835e412, 0x74795651, 0x28ca3506, 0x4071f739, + 0x032fdbf2, 0x097f7bc8, 0x44ced256, 0x47f25cb9, 0x43500684, 0x45481b9a, 0x5a5ecc82, 0x4fe9ed61, 0x337ee559, 0x556852b9, + 0x0b24b460, 0x696db949, 0x7a2def9d, 0x4fcd5640, 0x1babd707, 0x5c9254a3, 0x44d26e0d, 0x0e26b8e4, 0x3b1c3b5c, 0x0078c784, + 0x27a7dc96, 0x1d525589, 0x4384ae38, 0x447b77c3, 0x78488b8c, 0x5eab10f1, 0x16812737, 0x37cc8efa, 0x219cda83, 0x00bcc48f, + 0x3c667020, 0x492d7eaa, 0x710d06ce, 0x4172c47a, 0x358098ec, 0x1fff647b, 0x65672792, 0x1a7b927d, 0x24006275, 0x04e630a0, + 0x2f2a9185, 0x5873704b, 0x0a8c69bc, 0x06b49059, 0x49837c48, 0x4f90a2d0, 0x29ad7dd7, 0x3674be92, 0x46d5635f, 0x782758a2, + 0x721a2a75, 0x13427ca9, 0x20e03cc9, 0x5f884596, 0x19dc210f, 0x066c954d, 0x52f43f40, 0x5d9c256f, 0x7f0acaae, 0x1e186b81, + 0x55e9920f, 0x0e4f77b2, 0x6700ec53, 0x268837c0, 0x554ce08b, 0x4284e695, 0x2127e806, 0x384cb53b, 0x51076b2f, 0x23f9eb15}; // We don't need this generator in release. #ifdef TEST @@ -169,7 +90,7 @@ static uint64_t MMH_x[MMH_X_SIZE + 8] = { static void ink_init_MMH() { - srand48(13); // must remain the same! + srand48(13); // must remain the same! for (int i = 0; i < MMH_X_SIZE; i++) MMH_x[i] = lrand48(); } @@ -182,21 +103,21 @@ static inline void _memcpy(void *dest, const void *src, int nbytes) { for (int i = 0; i < nbytes; i++) - ((char *) dest)[i] = ((char *) src)[i]; + ((char *)dest)[i] = ((char *)src)[i]; } #define memcpy _memcpy #endif int -ink_code_incr_MMH_init(MMH_CTX * ctx) +ink_code_incr_MMH_init(MMH_CTX *ctx) { ctx->buffer_size = 0; ctx->blocks = 0; - ctx->state[0] = ((uint64_t) MMH_x[MMH_X_SIZE + 0] << 32) + MMH_x[MMH_X_SIZE + 1]; - ctx->state[1] = ((uint64_t) MMH_x[MMH_X_SIZE + 2] << 32) + MMH_x[MMH_X_SIZE + 3]; - ctx->state[2] = ((uint64_t) MMH_x[MMH_X_SIZE + 4] << 32) + MMH_x[MMH_X_SIZE + 5]; - ctx->state[3] = ((uint64_t) MMH_x[MMH_X_SIZE + 6] << 32) + MMH_x[MMH_X_SIZE + 7]; + ctx->state[0] = ((uint64_t)MMH_x[MMH_X_SIZE + 0] << 32) + MMH_x[MMH_X_SIZE + 1]; + ctx->state[1] = ((uint64_t)MMH_x[MMH_X_SIZE + 2] << 32) + MMH_x[MMH_X_SIZE + 3]; + ctx->state[2] = ((uint64_t)MMH_x[MMH_X_SIZE + 4] << 32) + MMH_x[MMH_X_SIZE + 5]; + ctx->state[3] = ((uint64_t)MMH_x[MMH_X_SIZE + 6] << 32) + MMH_x[MMH_X_SIZE + 7]; return 0; } @@ -205,15 +126,15 @@ ink_code_MMH(unsigned char *input, int len, unsigned char *sixteen_byte_hash) { MMH_CTX ctx; ink_code_incr_MMH_init(&ctx); - ink_code_incr_MMH_update(&ctx, (const char *) input, len); + ink_code_incr_MMH_update(&ctx, (const char *)input, len); ink_code_incr_MMH_final(sixteen_byte_hash, &ctx); return 0; } static inline void -MMH_update(MMH_CTX * ctx, unsigned char *ab) +MMH_update(MMH_CTX *ctx, unsigned char *ab) { - uint32_t *b = (uint32_t *) ab; + uint32_t *b = (uint32_t *)ab; ctx->state[0] += b[0] * MMH_x[(ctx->blocks + 0) % MMH_X_SIZE]; ctx->state[1] += b[1] * MMH_x[(ctx->blocks + 1) % MMH_X_SIZE]; ctx->state[2] += b[2] * MMH_x[(ctx->blocks + 2) % MMH_X_SIZE]; @@ -222,9 +143,9 @@ MMH_update(MMH_CTX * ctx, unsigned char *ab) } static inline void -MMH_updateb1(MMH_CTX * ctx, unsigned char *ab) +MMH_updateb1(MMH_CTX *ctx, unsigned char *ab) { - uint32_t *b = (uint32_t *) (ab - 1); + uint32_t *b = (uint32_t *)(ab - 1); uint32_t b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4]; b0 = (b0 << 8) + (b1 >> 24); b1 = (b1 << 8) + (b2 >> 24); @@ -238,9 +159,9 @@ MMH_updateb1(MMH_CTX * ctx, unsigned char *ab) } static inline void -MMH_updateb2(MMH_CTX * ctx, unsigned char *ab) +MMH_updateb2(MMH_CTX *ctx, unsigned char *ab) { - uint32_t *b = (uint32_t *) (ab - 2); + uint32_t *b = (uint32_t *)(ab - 2); uint32_t b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4]; b0 = (b0 << 16) + (b1 >> 16); b1 = (b1 << 16) + (b2 >> 16); @@ -254,9 +175,9 @@ MMH_updateb2(MMH_CTX * ctx, unsigned char *ab) } static inline void -MMH_updateb3(MMH_CTX * ctx, unsigned char *ab) +MMH_updateb3(MMH_CTX *ctx, unsigned char *ab) { - uint32_t *b = (uint32_t *) (ab - 3); + uint32_t *b = (uint32_t *)(ab - 3); uint32_t b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4]; b0 = (b0 << 24) + (b1 >> 8); b1 = (b1 << 24) + (b2 >> 8); @@ -270,9 +191,9 @@ MMH_updateb3(MMH_CTX * ctx, unsigned char *ab) } static inline void -MMH_updatel1(MMH_CTX * ctx, unsigned char *ab) +MMH_updatel1(MMH_CTX *ctx, unsigned char *ab) { - uint32_t *b = (uint32_t *) (ab - 1); + uint32_t *b = (uint32_t *)(ab - 1); uint32_t b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4]; b0 = (b0 >> 8) + (b1 << 24); b1 = (b1 >> 8) + (b2 << 24); @@ -286,9 +207,9 @@ MMH_updatel1(MMH_CTX * ctx, unsigned char *ab) } static inline void -MMH_updatel2(MMH_CTX * ctx, unsigned char *ab) +MMH_updatel2(MMH_CTX *ctx, unsigned char *ab) { - uint32_t *b = (uint32_t *) (ab - 2); + uint32_t *b = (uint32_t *)(ab - 2); uint32_t b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4]; b0 = (b0 >> 16) + (b1 << 16); b1 = (b1 >> 16) + (b2 << 16); @@ -302,9 +223,9 @@ MMH_updatel2(MMH_CTX * ctx, unsigned char *ab) } static inline void -MMH_updatel3(MMH_CTX * ctx, unsigned char *ab) +MMH_updatel3(MMH_CTX *ctx, unsigned char *ab) { - uint32_t *b = (uint32_t *) (ab - 3); + uint32_t *b = (uint32_t *)(ab - 3); uint32_t b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4]; b0 = (b0 >> 24) + (b1 << 8); b1 = (b1 >> 24) + (b2 << 8); @@ -318,9 +239,9 @@ MMH_updatel3(MMH_CTX * ctx, unsigned char *ab) } int -ink_code_incr_MMH_update(MMH_CTX * ctx, const char *ainput, int input_length) +ink_code_incr_MMH_update(MMH_CTX *ctx, const char *ainput, int input_length) { - unsigned char *in = (unsigned char *) ainput; + unsigned char *in = (unsigned char *)ainput; unsigned char *end = in + input_length; if (ctx->buffer_size) { int l = 16 - ctx->buffer_size; @@ -336,7 +257,7 @@ ink_code_incr_MMH_update(MMH_CTX * ctx, const char *ainput, int input_length) } { // check alignment - int alignment = (int)((intptr_t) in & 0x3); + int alignment = (int)((intptr_t)in & 0x3); if (alignment) { #if defined(_BIG_ENDIAN) #define big_endian 1 @@ -344,7 +265,7 @@ ink_code_incr_MMH_update(MMH_CTX * ctx, const char *ainput, int input_length) #define big_endian 0 #else unsigned int endian = 1; - int big_endian = !*(char *) &endian; + int big_endian = !*(char *)&endian; #endif if (big_endian) { if (alignment == 1) { @@ -389,11 +310,11 @@ ink_code_incr_MMH_update(MMH_CTX * ctx, const char *ainput, int input_length) Lstore: if (end - in) { int oldbs = ctx->buffer_size; - ctx->buffer_size += (int) (end - in); + ctx->buffer_size += (int)(end - in); #ifndef TEST ink_assert(ctx->buffer_size < 16); #endif - memcpy(ctx->buffer + oldbs, in, (int) (end - in)); + memcpy(ctx->buffer + oldbs, in, (int)(end - in)); } return 0; } @@ -405,18 +326,18 @@ Lstore: inline void _memset(unsigned char *b, int c, int len) { - (void) c; + (void)c; int o = len & 0x3, i; for (i = 0; i < o; i++) b[i] = 0; for (i = 0; i < (len - o) / 4; i++) - ((uint32_t *) (b + o))[i] = 0; + ((uint32_t *)(b + o))[i] = 0; } #endif int -ink_code_incr_MMH_final(uint8_t *presult, MMH_CTX * ctx) +ink_code_incr_MMH_final(uint8_t *presult, MMH_CTX *ctx) { unsigned int len = ctx->blocks * 4 + ctx->buffer_size; // pad out to 16 bytes @@ -426,12 +347,12 @@ ink_code_incr_MMH_final(uint8_t *presult, MMH_CTX * ctx) MMH_update(ctx, ctx->buffer); } // append length (before padding) - unsigned int *pbuffer = (unsigned int *) ctx->buffer; + unsigned int *pbuffer = (unsigned int *)ctx->buffer; pbuffer[1] = pbuffer[2] = pbuffer[3] = pbuffer[0] = len; MMH_update(ctx, ctx->buffer); // final phase - uint32_t *b = (uint32_t *) presult; - uint64_t d = (((uint64_t) 1) << 32) + 15; + uint32_t *b = (uint32_t *)presult; + uint64_t d = (((uint64_t)1) << 32) + 15; uint32_t b0 = uint32_t(ctx->state[0] % d); uint32_t b1 = uint32_t(ctx->state[1] % d); uint32_t b2 = uint32_t(ctx->state[2] % d); @@ -439,11 +360,8 @@ ink_code_incr_MMH_final(uint8_t *presult, MMH_CTX * ctx) // scramble the bits, losslessly (reversibly) b[0] = b0; b[1] = b1 ^ (b0 >> 24) ^ (b0 << 8); - b[2] = b2 ^ (b1 >> 16) ^ (b1 << 16) - ^ (b0 >> 24) ^ (b0 << 8); - b[3] = b3 ^ (b1 >> 8) ^ (b1 << 24) - ^ (b2 >> 16) ^ (b2 << 16) - ^ (b0 >> 24) ^ (b0 << 8); + b[2] = b2 ^ (b1 >> 16) ^ (b1 << 16) ^ (b0 >> 24) ^ (b0 << 8); + b[3] = b3 ^ (b1 >> 8) ^ (b1 << 24) ^ (b2 >> 16) ^ (b2 << 16) ^ (b0 >> 24) ^ (b0 << 8); b0 = b[0]; b1 = b[1]; @@ -451,25 +369,25 @@ ink_code_incr_MMH_final(uint8_t *presult, MMH_CTX * ctx) b3 = b[3]; b[2] = b2 ^ (b3 >> 24) ^ (b3 << 8); - b[1] = b1 ^ (b2 >> 16) ^ (b2 << 16) - ^ (b3 >> 24) ^ (b3 << 8); - b[0] = b0 ^ (b3 >> 8) ^ (b3 << 24) - ^ (b2 >> 16) ^ (b2 << 16) - ^ (b1 >> 24) ^ (b1 << 8); + b[1] = b1 ^ (b2 >> 16) ^ (b2 << 16) ^ (b3 >> 24) ^ (b3 << 8); + b[0] = b0 ^ (b3 >> 8) ^ (b3 << 24) ^ (b2 >> 16) ^ (b2 << 16) ^ (b1 >> 24) ^ (b1 << 8); return 0; } -MMHContext::MMHContext() { +MMHContext::MMHContext() +{ ink_code_incr_MMH_init(&_ctx); } bool -MMHContext::update(void const* data, int length) { - return 0 == ink_code_incr_MMH_update(&_ctx, static_cast<char const*>(data), length); +MMHContext::update(void const *data, int length) +{ + return 0 == ink_code_incr_MMH_update(&_ctx, static_cast<char const *>(data), length); } bool -MMHContext::finalize(CryptoHash& hash) { +MMHContext::finalize(CryptoHash &hash) +{ return 0 == ink_code_incr_MMH_final(hash.u8, &_ctx); } @@ -478,7 +396,7 @@ MMHContext::finalize(CryptoHash& hash) { #define TEST_COLLISIONS 10000000 static int -xxcompar(uint32_t ** x, uint32_t ** y) +xxcompar(uint32_t **x, uint32_t **y) { for (int i = 0; i < 4; i++) { if (x[i] > y[i]) @@ -495,8 +413,7 @@ double *xf; main() { - union - { + union { unsigned char hash[16]; uint32_t h[4]; } h; @@ -509,13 +426,13 @@ main() char *sc2 = "http://npdev:19080/1.8666000000/4000"; char *sc3 = "http://:@npdev/1.6664000000/4000;?"; char *sc4 = "http://:@npdev/1.8666000000/4000;?"; - ink_code_MMH((unsigned char *) sc1, strlen(sc1), h.hash); + ink_code_MMH((unsigned char *)sc1, strlen(sc1), h.hash); printf("%X %X %X %X\n", h.h[0], h.h[1], h.h[2], h.h[3]); - ink_code_MMH((unsigned char *) sc2, strlen(sc2), h.hash); + ink_code_MMH((unsigned char *)sc2, strlen(sc2), h.hash); printf("%X %X %X %X\n", h.h[0], h.h[1], h.h[2], h.h[3]); - ink_code_MMH((unsigned char *) sc3, strlen(sc3), h.hash); + ink_code_MMH((unsigned char *)sc3, strlen(sc3), h.hash); printf("%X %X %X %X\n", h.h[0], h.h[1], h.h[2], h.h[3]); - ink_code_MMH((unsigned char *) sc4, strlen(sc4), h.hash); + ink_code_MMH((unsigned char *)sc4, strlen(sc4), h.hash); printf("%X %X %X %X\n", h.h[0], h.h[1], h.h[2], h.h[3]); srand48(time(NULL)); @@ -523,16 +440,16 @@ main() char xs[256]; xf[xx] = drand48(); sprintf(xs, "http://@npdev/%16.14f/4000;?", xf[xx]); - ink_code_MMH((unsigned char *) xs, strlen(xs), (unsigned char *) &xxh[xx]); + ink_code_MMH((unsigned char *)xs, strlen(xs), (unsigned char *)&xxh[xx]); } qsort(xxh, TEST_COLLISIONS, 16, xxcompar); for (int xy = 0; xy < TEST_COLLISIONS - 1; xy++) { - if (xxh[xy][0] == xxh[xy + 1][0] && - xxh[xy][1] == xxh[xy + 1][1] && xxh[xy][2] == xxh[xy + 1][2] && xxh[xy][3] == xxh[xy + 1][3]) + if (xxh[xy][0] == xxh[xy + 1][0] && xxh[xy][1] == xxh[xy + 1][1] && xxh[xy][2] == xxh[xy + 1][2] && + xxh[xy][3] == xxh[xy + 1][3]) printf("********** collision %d\n", xy); } - unsigned char *s = (unsigned char *) MMH_x; + unsigned char *s = (unsigned char *)MMH_x; int l = sizeof(MMH_x); unsigned char *s1 = (unsigned char *)ats_malloc(l + 3); s1 += 1; @@ -560,10 +477,10 @@ main() printf("test chunking\n"); ink_code_incr_MMH_init(&c); for (i = 0; i < 24; i++) { - ink_code_incr_MMH_update(&c, (char *) t, i); + ink_code_incr_MMH_update(&c, (char *)t, i); t += i; } - ink_code_incr_MMH_final((char *) h.hash, &c); + ink_code_incr_MMH_final((char *)h.hash, &c); printf("%X %X %X %X\n", h.h[0], h.h[1], h.h[2], h.h[3]); int q = t - s; ink_code_MMH(s, q, h.hash); @@ -575,7 +492,7 @@ main() memset(hist, 0, sizeof(hist)); size_t xx; while (((xx = fread(x, 1, 128, fp)) == 128)) { - ink_code_MMH((unsigned char *) x, 128, h.hash); + ink_code_MMH((unsigned char *)x, 128, h.hash); hist[h.h[0] & 255]++; } for (int z = 0; z < 256; z++) { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/65477944/lib/ts/MMH.h ---------------------------------------------------------------------- diff --git a/lib/ts/MMH.h b/lib/ts/MMH.h index 74f2c3c..a886bdf 100644 --- a/lib/ts/MMH.h +++ b/lib/ts/MMH.h @@ -22,14 +22,13 @@ */ #ifndef _MMH_h_ -#define _MMH_h_ +#define _MMH_h_ #include "ink_code.h" #include "ink_defs.h" #include "CryptoHash.h" -struct MMH_CTX -{ +struct MMH_CTX { uint64_t state[4]; unsigned char buffer[32]; int buffer_size; @@ -39,9 +38,9 @@ struct MMH_CTX // signed-unsigned-const gratuitous differences brought // to you by history and the ANSI committee -int inkcoreapi ink_code_incr_MMH_init(MMH_CTX * context); -int inkcoreapi ink_code_incr_MMH_update(MMH_CTX * context, const char *input, int input_length); -int inkcoreapi ink_code_incr_MMH_final(uint8_t *sixteen_byte_hash_pointer, MMH_CTX * context); +int inkcoreapi ink_code_incr_MMH_init(MMH_CTX *context); +int inkcoreapi ink_code_incr_MMH_update(MMH_CTX *context, const char *input, int input_length); +int inkcoreapi ink_code_incr_MMH_final(uint8_t *sixteen_byte_hash_pointer, MMH_CTX *context); int inkcoreapi ink_code_MMH(unsigned char *input, int len, unsigned char *sixteen_byte_hash); /** @@ -54,13 +53,14 @@ class MMHContext : public CryptoContext { protected: MMH_CTX _ctx; + public: MMHContext(); /// Update the hash with @a data of @a length bytes. - virtual bool update(void const* data, int length); + virtual bool update(void const *data, int length); /// Finalize and extract the @a hash. - virtual bool finalize(CryptoHash& hash); -# if 0 + virtual bool finalize(CryptoHash &hash); +#if 0 MMH & loadFromBuffer(char *MMH_buf) { int i; @@ -113,7 +113,7 @@ public: { return ink_code_md5_stringify_fast(hex_MMH, str()); } -# endif +#endif }; #endif
