mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'devel' of ssh://github.com/triAGENS/ArangoDB into devel
This commit is contained in:
commit
a3596a6013
|
@ -170,7 +170,8 @@ struct current {
|
|||
size_t pos; /* Cursor position, measured in chars */
|
||||
int cols; /* Size of the window, in chars */
|
||||
int rows; /* Screen rows */
|
||||
const char *prompt;
|
||||
const char *prompt; /*string with control charaters for displaying the prompt */
|
||||
size_t pchars; /*number of visible charaters in the prompt */
|
||||
char *capture; /* Allocated capture buffer, or NULL for none. Always null terminated */
|
||||
#if defined(USE_TERMIOS)
|
||||
int fd; /* Terminal fd */
|
||||
|
@ -314,12 +315,11 @@ static void clearScreen(struct current *current)
|
|||
|
||||
static void cursorToLeft(struct current *current)
|
||||
{
|
||||
size_t pchars = 20;
|
||||
/**
|
||||
* how many lines are need to display the current->pos characters of the
|
||||
* current buffer
|
||||
*/
|
||||
size_t number_lines = new_line_numbers(current->pos, current->cols, pchars);
|
||||
size_t number_lines = new_line_numbers(current->pos, current->cols, current->pchars);
|
||||
/**
|
||||
* move cursor number_lines above
|
||||
*/
|
||||
|
@ -349,11 +349,10 @@ static void outputControlChar(struct current *current, char ch)
|
|||
|
||||
static void eraseEol(struct current *current)
|
||||
{
|
||||
size_t pchars = 20;
|
||||
/**
|
||||
* number of additional lines to display chars characters (the quite buffer)
|
||||
*/
|
||||
size_t number_lines = new_line_numbers(current->chars, current->cols, pchars);
|
||||
size_t number_lines = new_line_numbers(current->chars, current->cols, current->pchars);
|
||||
|
||||
size_t i;
|
||||
/**
|
||||
|
@ -1025,101 +1024,7 @@ static void refreshPage(const struct linenoiseCompletions * lc, struct current *
|
|||
#ifndef USE_WINCONSOLE
|
||||
static void refreshLine(const char *prompt, struct current *current)
|
||||
{
|
||||
refreshMultiLine(prompt, current);return;
|
||||
size_t plen;
|
||||
size_t pchars;
|
||||
int backup = 0;
|
||||
int i;
|
||||
const char *buf = current->buf;
|
||||
size_t chars = current->chars;
|
||||
size_t pos = current->pos;
|
||||
int b;
|
||||
int ch;
|
||||
int n;
|
||||
|
||||
/* Should intercept SIGWINCH. For now, just get the size every time */
|
||||
getWindowSize(current);
|
||||
|
||||
plen = strlen(prompt);
|
||||
pchars = utf8_strlen(prompt, plen);
|
||||
/* Scan the prompt for embedded ansi color control sequences and
|
||||
* discount them as characters/columns.
|
||||
*/
|
||||
pchars -= countColorControlChars(prompt);
|
||||
|
||||
/* Account for a line which is too long to fit in the window.
|
||||
* Note that control chars require an extra column
|
||||
*/
|
||||
|
||||
/* How many cols are required to the left of 'pos'?
|
||||
* The prompt, plus one extra for each control char
|
||||
*/
|
||||
n = pchars + utf8_strlen(buf, current->len);
|
||||
b = 0;
|
||||
for (i = 0; i < pos; i++) {
|
||||
b += utf8_tounicode(buf + b, &ch);
|
||||
if (ch < ' ') {
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
/* If too many are needed, strip chars off the front of 'buf'
|
||||
* until it fits. Note that if the current char is a control character,
|
||||
* we need one extra col.
|
||||
*/
|
||||
if (current->pos < current->chars && get_char(current, current->pos) < ' ') {
|
||||
n++;
|
||||
}
|
||||
|
||||
while (n >= current->cols && pos > 0) {
|
||||
b = utf8_tounicode(buf, &ch);
|
||||
if (ch < ' ') {
|
||||
n--;
|
||||
}
|
||||
n--;
|
||||
buf += b;
|
||||
pos--;
|
||||
chars--;
|
||||
}
|
||||
|
||||
/* Cursor to left edge, then the prompt */
|
||||
cursorToLeft(current);
|
||||
outputChars(current, prompt, plen);
|
||||
|
||||
/* Now the current buffer content */
|
||||
|
||||
/* Need special handling for control characters.
|
||||
* If we hit 'cols', stop.
|
||||
*/
|
||||
b = 0; /* unwritted bytes */
|
||||
n = 0; /* How many control chars were written */
|
||||
for (i = 0; i < chars; i++) {
|
||||
int ch2;
|
||||
int w = utf8_tounicode(buf + b, &ch2);
|
||||
if (ch2 < ' ') {
|
||||
n++;
|
||||
}
|
||||
if (pchars + i + n >= current->cols) {
|
||||
break;
|
||||
}
|
||||
if (ch2 < ' ') {
|
||||
/* A control character, so write the buffer so far */
|
||||
outputChars(current, buf, b);
|
||||
buf += b + w;
|
||||
b = 0;
|
||||
outputControlChar(current, ch2 + '@');
|
||||
if (i < pos) {
|
||||
backup++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
b += w;
|
||||
}
|
||||
}
|
||||
outputChars(current, buf, b);
|
||||
/* Erase to right, move cursor to original position */
|
||||
eraseEol(current);
|
||||
setCursorPos(current, pos + pchars + backup );
|
||||
refreshMultiLine(prompt, current);
|
||||
}
|
||||
|
||||
static void showBuffer(struct current * current, size_t pchars) {
|
||||
|
@ -1127,27 +1032,6 @@ static void showBuffer(struct current * current, size_t pchars) {
|
|||
size_t buf_len = strlen(buf);
|
||||
outputChars(current, buf, buf_len);
|
||||
return;
|
||||
/**
|
||||
* number of additional lines for displaying
|
||||
* the complete buffer
|
||||
*/
|
||||
size_t free_chars = current->cols - pchars;
|
||||
if(current->chars <= free_chars) {
|
||||
outputChars(current, buf, buf_len);
|
||||
} else {
|
||||
size_t number_lines = new_line_numbers(current->chars, current->cols, pchars);
|
||||
int i;
|
||||
outputChars(current, buf, free_chars);
|
||||
// newLine(current);
|
||||
buf = buf + free_chars;
|
||||
for(i=1; i<= number_lines-1; i++) {
|
||||
outputChars(current, buf, current->cols);
|
||||
// newLine(current);
|
||||
buf = buf + current->cols;
|
||||
}
|
||||
buf_len = strlen(buf);
|
||||
outputChars(current, buf, buf_len);
|
||||
}
|
||||
}
|
||||
static void refreshMultiLine(const char *prompt, struct current *current)
|
||||
{
|
||||
|
@ -1158,12 +1042,7 @@ static void refreshMultiLine(const char *prompt, struct current *current)
|
|||
getWindowSize(current);
|
||||
|
||||
plen = strlen(prompt);
|
||||
pchars = utf8_strlen(prompt, plen);
|
||||
/* Scan the prompt for embedded ansi color control sequences and
|
||||
* discount them as characters/columns.
|
||||
*/
|
||||
pchars -= countColorControlChars(prompt);
|
||||
|
||||
pchars = current->pchars;
|
||||
|
||||
/* Cursor to left edge, then the prompt */
|
||||
// cursorToLeft(current);
|
||||
|
@ -1583,8 +1462,7 @@ static void moveCursorToRight(struct current * current) {
|
|||
}
|
||||
#else
|
||||
static void moveCursorToLeft(struct current * current) {
|
||||
size_t pchars = 20;
|
||||
int x = next_allowed_x(current->pos + 1, current->cols, pchars);
|
||||
int x = next_allowed_x(current->pos + 1, current->cols, current->pchars);
|
||||
if(x==0) {
|
||||
fd_printf(current->fd, "\x1b[1A\x1b[%dG", current->cols);
|
||||
} else {
|
||||
|
@ -1592,8 +1470,7 @@ static void moveCursorToLeft(struct current * current) {
|
|||
}
|
||||
}
|
||||
static void moveCursorToRight(struct current * current) {
|
||||
size_t pchars = 20;
|
||||
int x = next_allowed_x(current->pos-1, current->cols, pchars);
|
||||
int x = next_allowed_x(current->pos-1, current->cols, current->pchars);
|
||||
if(current->pos>current->chars) {
|
||||
return;
|
||||
}
|
||||
|
@ -1665,9 +1542,9 @@ process_char:
|
|||
}
|
||||
/* Otherwise fall through to delete char to right of cursor */
|
||||
case SPECIAL_DELETE:
|
||||
if (remove_char(current, current->pos) == 1) {
|
||||
refreshLine(current->prompt, current);
|
||||
}
|
||||
eraseEol(current);
|
||||
remove_char(current, current->pos);
|
||||
refreshLine(current->prompt, current);
|
||||
break;
|
||||
case SPECIAL_INSERT:
|
||||
/* Ignore. Expansion Hook.
|
||||
|
@ -1690,9 +1567,9 @@ process_char:
|
|||
pos--;
|
||||
}
|
||||
|
||||
if (remove_chars(current, pos, current->pos - pos)) {
|
||||
refreshLine(current->prompt, current);
|
||||
}
|
||||
remove_chars(current, pos, current->pos - pos);
|
||||
refreshLine(current->prompt, current);
|
||||
|
||||
}
|
||||
break;
|
||||
case ctrl('R'): /* ctrl-r */
|
||||
|
@ -1951,12 +1828,18 @@ char *linenoise(const char *prompt)
|
|||
}
|
||||
else
|
||||
{
|
||||
size_t pchars = utf8_strlen(prompt, strlen(prompt));
|
||||
/* Scan the prompt for embedded ansi color control sequences and
|
||||
* discount them as characters/columns.
|
||||
*/
|
||||
pchars -= countColorControlChars(prompt);
|
||||
current.buf = buf;
|
||||
current.bufmax = sizeof(buf);
|
||||
current.len = 0;
|
||||
current.chars = 0;
|
||||
current.pos = 0;
|
||||
current.prompt = prompt;
|
||||
current.pchars = pchars;
|
||||
current.capture = NULL;
|
||||
|
||||
initLinenoiseLine(¤t);
|
||||
|
|
|
@ -71,96 +71,114 @@ BOOST_AUTO_TEST_CASE (tst_fnv64_simple) {
|
|||
buffer = "";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 14695981039346656037ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 14695981039346656037ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 14695981039346656037ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = " ";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638117931323064703ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638117931323064703ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638117931323064703ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = " ";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 560038479724991597ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 560038479724991597ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 560038479724991597ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "a";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638187200555641996ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638187200555641996ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638187200555641996ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "A";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638222384927744748ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638222384927744748ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638222384927744748ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
buffer = " a";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 559967011469157882ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 559967011469157882ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 559967011469157882ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = " a ";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 14038824050427892078ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 14038824050427892078ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 14038824050427892078ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "a ";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 620373080799520836ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 620373080799520836ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 620373080799520836ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "A ";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 650913115778654372ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 650913115778654372ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 650913115778654372ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = " A";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 560002195841260634ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 560002195841260634ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 560002195841260634ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = " A ";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 14069504822895436622ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 14069504822895436622ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 14069504822895436622ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "0";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638135523509116079ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638135523509116079ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638135523509116079ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "1";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638134423997487868ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638134423997487868ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638134423997487868ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "11";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 574370613795883607ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 574370613795883607ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 574370613795883607ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "111";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 5002439360283388754ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 5002439360283388754ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 5002439360283388754ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "2";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638137722532372501ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638137722532372501ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638137722532372501ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "3";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638136623020744290ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638136623020744290ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 12638136623020744290ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "the quick brown fox jumped over the lazy dog";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 5742411339260295416ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 5742411339260295416ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 5742411339260295416ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "The Quick Brown Fox Jumped Over The Lazy Dog";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 11643291398347681368ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 11643291398347681368ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 11643291398347681368ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -173,51 +191,61 @@ BOOST_AUTO_TEST_CASE (tst_fnv64_utf8) {
|
|||
buffer = "ジャパン は、イギリスのニュー・ウェーヴバンド。デヴィッド・ ... を構築していった。 日本では初来日でいきなり武道館での公演を行うなど、爆発的な人気を誇ったが、英国ではなかなか人気が出ず、初期は典型的な「ビッグ・イン・ジャパン」状態であった。日本最大級のポータルサイト。検索、オークション、ニュース、メール、コミュニティ、ショッピング、など80以上のサービスを展開。あなたの生活をより豊かにする「ライフ・エンジン」を目指していきます。デヴィッド・シルヴィアンとその弟スティーヴ・ジャンセン、デヴィッドの親友であったミック・カーンを中心に結成。ミック・カーンの兄の結婚式にバンドとして最初のお披露目をした。当初はミック・カーンをリードボーカルとして練習していたが、本番直前になって怖じ気づいたミックがデヴィッド・シルヴィアンに無理矢理頼み込んでボーカルを代わってもらい、以降デヴィッドがリードボーカルとなった。その後高校の同級であったリチャード・バルビエリを誘い、更にオーディションでロブ・ディーンを迎え入れ、デビュー当初のバンドの形態となった。デビュー当初はアイドルとして宣伝されたグループだったが、英国の音楽シーンではほとんど人気が無かった。初期のサウンドは主に黒人音楽やグラムロックをポスト・パンク的に再解釈したものであったが、作品を重ねるごとに耽美的な作風、退廃的な歌詞やシンセサイザーの利用など独自のスタイルを構築していった。日本では初来日でいきなり武道館での公演を行うなど、爆発的な人気を誇ったが、英国ではなかなか人気が出ず、初期は典型的な「ビッグ・イン・ジャパン」状態であった。";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 211184911024797733ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 211184911024797733ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 211184911024797733ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "코리아닷컴 메일알리미 서비스 중단안내 [안내] 개인정보취급방침 변경 안내 회사소개 | 광고안내 | 제휴안내 | 개인정보취급방침 | 청소년보호정책 | 스팸방지정책 | 사이버고객센터 | 약관안내 | 이메일 무단수집거부 | 서비스 전체보기";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 270676307504294177ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 270676307504294177ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 270676307504294177ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "中华网以中国的市场为核心,致力为当地用户提供流动增值服务、网上娱乐及互联网服务。本公司亦推出网上游戏,及透过其门户网站提供包罗万有的网上产品及服务。";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 14670566365397374664ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 14670566365397374664ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 14670566365397374664ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "כפי שסופיה קופולה היטיבה לבטא בסרטה אבודים בטוקיו, בתי מלון יוקרתיים בערים גדולות אמנם מציעים אינספור פינוקים, אבל הם גם עלולים לגרום לנו להרגיש בודדים ואומללים מאי פעם. לעומת זאת, B&B, בתים פרטיים שבהם אפשר לישון ולאכול ארוחת בוקר, הם דרך נהדרת להכיר עיר אירופאית כמו מקומיים ולפגוש אנשים מרתקים מרחבי העולם. לטובת מי שנוסע לממלכה בחודשים הקרובים, הגרדיאן הבריטי קיבץ את עשרת ה-B&B המומלצים ביותר בלונדון. כל שנותר הוא לבחור, ולהזמין מראש";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 16145169633099782595ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 16145169633099782595ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 16145169633099782595ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "بان يأسف لمقتل لاجئين سوريين بتركيا المرزوقي يندد بعنف الأمن التونسي تنديد بقتل الجيش السوري مصورا تلفزيونيا 14 قتيلا وعشرات الجرحى بانفجار بالصومال";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 7398242043026945788ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 7398242043026945788ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 7398242043026945788ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "Голкипер мадридского «Реала» Икер Касильяс призвал своих партнеров сосредоточить все мысли на предстоящем дерби с «Атлетико»";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 10412552537249637418ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 10412552537249637418ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 10412552537249637418ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = " ";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 4095843978425089933ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 4095843978425089933ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 4095843978425089933ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "अ आ इ ई उ ऊ ऋ ॠ ऌ ॡ ए ऐ ओ औ क ख ग घ ङ च छ ज झ ञ ट ठ ड ढ ण त थ द ध न प फ ब भ म य र ल व श ष स ह";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2927729442665428350ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2927729442665428350ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2927729442665428350ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "tɜt kɐː mɔj ŋɨɜj siŋ za ɗew ɗɨɜk tɨɰ zɔ vɐː ɓiŋ ɗɐŋ vej ɲɜn fɜm vɐː kɨɜn. mɔj kɔn ŋɨɜj ɗeu ɗɨɜk tɐːw huɜ ɓɐːn cɔ li ci vɐː lɨɜŋ tɜm vɐː kɜn fɐːj ɗoj sɨ vɜj ɲɐw cɔŋ tiŋ ɓɐŋ hɨw.";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 15359789603011345030ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 15359789603011345030ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 15359789603011345030ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
|
||||
|
||||
buffer = "äöüßÄÖÜ€µ";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2954195900047086928ULL, TRI_FnvHashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2954195900047086928ULL, TRI_FnvHashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2954195900047086928ULL, TRI_FnvHashBlock(TRI_FnvHashBlockInitial(), buffer.c_str(), strlen(buffer.c_str())));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -332,51 +360,61 @@ BOOST_AUTO_TEST_CASE (tst_crc32_utf8) {
|
|||
buffer = "ジャパン は、イギリスのニュー・ウェーヴバンド。デヴィッド・ ... を構築していった。 日本では初来日でいきなり武道館での公演を行うなど、爆発的な人気を誇ったが、英国ではなかなか人気が出ず、初期は典型的な「ビッグ・イン・ジャパン」状態であった。日本最大級のポータルサイト。検索、オークション、ニュース、メール、コミュニティ、ショッピング、など80以上のサービスを展開。あなたの生活をより豊かにする「ライフ・エンジン」を目指していきます。デヴィッド・シルヴィアンとその弟スティーヴ・ジャンセン、デヴィッドの親友であったミック・カーンを中心に結成。ミック・カーンの兄の結婚式にバンドとして最初のお披露目をした。当初はミック・カーンをリードボーカルとして練習していたが、本番直前になって怖じ気づいたミックがデヴィッド・シルヴィアンに無理矢理頼み込んでボーカルを代わってもらい、以降デヴィッドがリードボーカルとなった。その後高校の同級であったリチャード・バルビエリを誘い、更にオーディションでロブ・ディーンを迎え入れ、デビュー当初のバンドの形態となった。デビュー当初はアイドルとして宣伝されたグループだったが、英国の音楽シーンではほとんど人気が無かった。初期のサウンドは主に黒人音楽やグラムロックをポスト・パンク的に再解釈したものであったが、作品を重ねるごとに耽美的な作風、退廃的な歌詞やシンセサイザーの利用など独自のスタイルを構築していった。日本では初来日でいきなり武道館での公演を行うなど、爆発的な人気を誇ったが、英国ではなかなか人気が出ず、初期は典型的な「ビッグ・イン・ジャパン」状態であった。";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 4162027650ULL, TRI_Crc32HashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 4162027650ULL, TRI_Crc32HashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 4162027650ULL, TRI_FinalCrc32(TRI_BlockCrc32(TRI_InitialCrc32(), buffer.c_str(), strlen(buffer.c_str()))));
|
||||
|
||||
|
||||
buffer = "코리아닷컴 메일알리미 서비스 중단안내 [안내] 개인정보취급방침 변경 안내 회사소개 | 광고안내 | 제휴안내 | 개인정보취급방침 | 청소년보호정책 | 스팸방지정책 | 사이버고객센터 | 약관안내 | 이메일 무단수집거부 | 서비스 전체보기";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2360481044ULL, TRI_Crc32HashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2360481044ULL, TRI_Crc32HashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2360481044ULL, TRI_FinalCrc32(TRI_BlockCrc32(TRI_InitialCrc32(), buffer.c_str(), strlen(buffer.c_str()))));
|
||||
|
||||
|
||||
buffer = "中华网以中国的市场为核心,致力为当地用户提供流动增值服务、网上娱乐及互联网服务。本公司亦推出网上游戏,及透过其门户网站提供包罗万有的网上产品及服务。";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 644060807ULL, TRI_Crc32HashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 644060807ULL, TRI_Crc32HashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 644060807ULL, TRI_FinalCrc32(TRI_BlockCrc32(TRI_InitialCrc32(), buffer.c_str(), strlen(buffer.c_str()))));
|
||||
|
||||
|
||||
buffer = "כפי שסופיה קופולה היטיבה לבטא בסרטה אבודים בטוקיו, בתי מלון יוקרתיים בערים גדולות אמנם מציעים אינספור פינוקים, אבל הם גם עלולים לגרום לנו להרגיש בודדים ואומללים מאי פעם. לעומת זאת, B&B, בתים פרטיים שבהם אפשר לישון ולאכול ארוחת בוקר, הם דרך נהדרת להכיר עיר אירופאית כמו מקומיים ולפגוש אנשים מרתקים מרחבי העולם. לטובת מי שנוסע לממלכה בחודשים הקרובים, הגרדיאן הבריטי קיבץ את עשרת ה-B&B המומלצים ביותר בלונדון. כל שנותר הוא לבחור, ולהזמין מראש";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 1177579087ULL, TRI_Crc32HashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 1177579087ULL, TRI_Crc32HashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 1177579087ULL, TRI_FinalCrc32(TRI_BlockCrc32(TRI_InitialCrc32(), buffer.c_str(), strlen(buffer.c_str()))));
|
||||
|
||||
|
||||
buffer = "بان يأسف لمقتل لاجئين سوريين بتركيا المرزوقي يندد بعنف الأمن التونسي تنديد بقتل الجيش السوري مصورا تلفزيونيا 14 قتيلا وعشرات الجرحى بانفجار بالصومال";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 1650013020ULL, TRI_Crc32HashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 1650013020ULL, TRI_Crc32HashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 1650013020ULL, TRI_FinalCrc32(TRI_BlockCrc32(TRI_InitialCrc32(), buffer.c_str(), strlen(buffer.c_str()))));
|
||||
|
||||
|
||||
buffer = "Голкипер мадридского «Реала» Икер Касильяс призвал своих партнеров сосредоточить все мысли на предстоящем дерби с «Атлетико»";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 1084564896ULL, TRI_Crc32HashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 1084564896ULL, TRI_Crc32HashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 1084564896ULL, TRI_FinalCrc32(TRI_BlockCrc32(TRI_InitialCrc32(), buffer.c_str(), strlen(buffer.c_str()))));
|
||||
|
||||
|
||||
buffer = " ";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2342474570ULL, TRI_Crc32HashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2342474570ULL, TRI_Crc32HashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2342474570ULL, TRI_FinalCrc32(TRI_BlockCrc32(TRI_InitialCrc32(), buffer.c_str(), strlen(buffer.c_str()))));
|
||||
|
||||
|
||||
buffer = "अ आ इ ई उ ऊ ऋ ॠ ऌ ॡ ए ऐ ओ औ क ख ग घ ङ च छ ज झ ञ ट ठ ड ढ ण त थ द ध न प फ ब भ म य र ल व श ष स ह";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2714476779ULL, TRI_Crc32HashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2714476779ULL, TRI_Crc32HashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2714476779ULL, TRI_FinalCrc32(TRI_BlockCrc32(TRI_InitialCrc32(), buffer.c_str(), strlen(buffer.c_str()))));
|
||||
|
||||
|
||||
buffer = "tɜt kɐː mɔj ŋɨɜj siŋ za ɗew ɗɨɜk tɨɰ zɔ vɐː ɓiŋ ɗɐŋ vej ɲɜn fɜm vɐː kɨɜn. mɔj kɔn ŋɨɜj ɗeu ɗɨɜk tɐːw huɜ ɓɐːn cɔ li ci vɐː lɨɜŋ tɜm vɐː kɜn fɐːj ɗoj sɨ vɜj ɲɐw cɔŋ tiŋ ɓɐŋ hɨw.";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 3194095589ULL, TRI_Crc32HashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 3194095589ULL, TRI_Crc32HashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 3194095589ULL, TRI_FinalCrc32(TRI_BlockCrc32(TRI_InitialCrc32(), buffer.c_str(), strlen(buffer.c_str()))));
|
||||
|
||||
|
||||
buffer = "äöüßÄÖÜ€µ";
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2590070434ULL, TRI_Crc32HashString(buffer.c_str()));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2590070434ULL, TRI_Crc32HashPointer(buffer.c_str(), strlen(buffer.c_str())));
|
||||
BOOST_CHECK_EQUAL((uint64_t) 2590070434ULL, TRI_FinalCrc32(TRI_BlockCrc32(TRI_InitialCrc32(), buffer.c_str(), strlen(buffer.c_str()))));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -491,6 +491,30 @@ BOOST_AUTO_TEST_CASE (tst_duplicate_keys) {
|
|||
/// @brief test hashing
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
BOOST_AUTO_TEST_CASE (tst_json_hash_utf8) {
|
||||
TRI_json_t* json;
|
||||
|
||||
json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, "\"äöüßÄÖÜ€µ\"");
|
||||
BOOST_CHECK_EQUAL(17926322495289827824ULL, TRI_HashJson(json));
|
||||
FREE_JSON
|
||||
|
||||
json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, "\"코리아닷컴 메일알리미 서비스 중단안내 [안내] 개인정보취급방침 변경 안내 회사소개 | 광고안내 | 제휴안내 | 개인정보취급방침 | 청소년보호정책 | 스팸방지정책 | 사이버고객센터 | 약관안내 | 이메일 무단수집거부 | 서비스 전체보기\"");
|
||||
BOOST_CHECK_EQUAL(11647939066062684691ULL, TRI_HashJson(json));
|
||||
FREE_JSON
|
||||
|
||||
json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, "\"بان يأسف لمقتل لاجئين سوريين بتركيا المرزوقي يندد بعنف الأمن التونسي تنديد بقتل الجيش السوري مصورا تلفزيونيا 14 قتيلا وعشرات الجرحى بانفجار بالصومال\"");
|
||||
BOOST_CHECK_EQUAL(9773937585298648628ULL, TRI_HashJson(json));
|
||||
FREE_JSON
|
||||
|
||||
json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, "\"中华网以中国的市场为核心,致力为当地用户提供流动增值服务、网上娱乐及互联网服务。本公司亦推出网上游戏,及透过其门户网站提供包罗万有的网上产品及服务。\"");
|
||||
BOOST_CHECK_EQUAL(5348732066920102360ULL, TRI_HashJson(json));
|
||||
FREE_JSON
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test hashing
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
BOOST_AUTO_TEST_CASE (tst_json_hash) {
|
||||
TRI_json_t* json;
|
||||
|
||||
|
|
|
@ -506,7 +506,7 @@ static int ResizeMultiPointer (TRI_multi_pointer_t* array, size_t size) {
|
|||
oldTable = array->_table;
|
||||
oldAlloc = array->_nrAlloc;
|
||||
|
||||
array->_nrAlloc = TRI_NextPrime((uint64_t) size);
|
||||
array->_nrAlloc = TRI_NearPrime((uint64_t) size);
|
||||
array->_table_alloc = TRI_Allocate(array->_memoryZone,
|
||||
array->_nrAlloc * sizeof(TRI_multi_pointer_entry_t) + 64,true);
|
||||
array->_table = (TRI_multi_pointer_entry_t*)
|
||||
|
|
|
@ -31,6 +31,20 @@
|
|||
// --SECTION-- FNV
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private functions for FNV
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief the FNV hash work horse
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static inline uint64_t FnvWork (uint8_t value, uint64_t hash) {
|
||||
static const uint64_t MagicPrime = 0x00000100000001b3ULL;
|
||||
|
||||
return (hash ^ value) * MagicPrime;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- public functions for FNV
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -41,11 +55,18 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief computes a FNV hash for blobs
|
||||
/// @brief computes a FNV hash for strings with a length
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
uint64_t TRI_FnvHashBlob (TRI_blob_t* blob) {
|
||||
return TRI_FnvHashPointer(blob->data, blob->length);
|
||||
uint64_t TRI_FnvHashBlock (uint64_t hash, void const* buffer, size_t length) {
|
||||
uint8_t const* p = (uint8_t const*) buffer;
|
||||
uint8_t const* end = p + length;
|
||||
|
||||
while (p < end) {
|
||||
hash = FnvWork(*p++, hash);
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -53,23 +74,15 @@ uint64_t TRI_FnvHashBlob (TRI_blob_t* blob) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
uint64_t TRI_FnvHashPointer (void const* buffer, size_t length) {
|
||||
uint64_t nMagicPrime;
|
||||
uint64_t nHashVal;
|
||||
uint8_t const* pFirst;
|
||||
uint8_t const* pLast;
|
||||
return TRI_FnvHashBlock(0xcbf29ce484222325ULL, buffer, length);
|
||||
}
|
||||
|
||||
nMagicPrime = 0x00000100000001b3ULL;
|
||||
nHashVal = 0xcbf29ce484222325ULL;
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief computes a FNV hash for blobs
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pFirst = (uint8_t const*) buffer;
|
||||
pLast = pFirst + length;
|
||||
|
||||
while (pFirst < pLast) {
|
||||
nHashVal ^= *pFirst++;
|
||||
nHashVal *= nMagicPrime;
|
||||
}
|
||||
|
||||
return nHashVal;
|
||||
uint64_t TRI_FnvHashBlob (TRI_blob_t* blob) {
|
||||
return TRI_FnvHashPointer(blob->data, blob->length);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -94,23 +107,6 @@ uint64_t TRI_FnvHashString (char const* buffer) {
|
|||
return nHashVal;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief computes a FNV hash for strings with a length
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
uint64_t TRI_FnvHashBlock (uint64_t hash, char const* buffer, size_t length) {
|
||||
uint64_t nMagicPrime;
|
||||
size_t j;
|
||||
|
||||
nMagicPrime = 0x00000100000001b3ULL;
|
||||
|
||||
for (j = 0; j < length; ++j) {
|
||||
hash ^= buffer[j];
|
||||
hash *= nMagicPrime;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief computes a initial FNV for blocks
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -48,10 +48,10 @@ extern "C" {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief computes a FNV hash for blobs
|
||||
/// @brief computes a FNV hash for blocks
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
uint64_t TRI_FnvHashBlob (TRI_blob_t*);
|
||||
uint64_t TRI_FnvHashBlock (uint64_t, void const*, size_t);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief computes a FNV hash for memory blobs
|
||||
|
@ -59,18 +59,18 @@ uint64_t TRI_FnvHashBlob (TRI_blob_t*);
|
|||
|
||||
uint64_t TRI_FnvHashPointer (void const*, size_t);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief computes a FNV hash for blobs
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
uint64_t TRI_FnvHashBlob (TRI_blob_t*);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief computes a FNV hash for strings
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
uint64_t TRI_FnvHashString (char const*);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief computes a FNV hash for blocks
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
uint64_t TRI_FnvHashBlock (uint64_t, char const*, size_t);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief computes a initial FNV for blocks
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -767,6 +767,25 @@ TRI_json_t* TRI_MergeJson (TRI_memory_zone_t* zone,
|
|||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief computes a FNV hash for strings with a length
|
||||
/// this function has an influence on how keys are distributed to shards
|
||||
/// change with caution!
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static uint64_t HashBlock (uint64_t hash, char const* buffer, size_t length) {
|
||||
uint64_t nMagicPrime;
|
||||
size_t j;
|
||||
|
||||
nMagicPrime = 0x00000100000001b3ULL;
|
||||
|
||||
for (j = 0; j < length; ++j) {
|
||||
hash ^= buffer[j];
|
||||
hash *= nMagicPrime;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief compute a hash value for a JSON document, starting with a given
|
||||
/// initial hash value. Note that a NULL pointer for json hashes to the
|
||||
|
@ -780,7 +799,7 @@ static uint64_t HashJsonRecursive (uint64_t hash, TRI_json_t const* object) {
|
|||
TRI_json_t const* subjson;
|
||||
|
||||
if (0 == object) {
|
||||
return TRI_FnvHashBlock(hash, "null", 4); // strlen("null")
|
||||
return HashBlock(hash, "null", 4); // strlen("null")
|
||||
}
|
||||
switch (object->_type) {
|
||||
case TRI_JSON_UNUSED: {
|
||||
|
@ -788,31 +807,31 @@ static uint64_t HashJsonRecursive (uint64_t hash, TRI_json_t const* object) {
|
|||
}
|
||||
|
||||
case TRI_JSON_NULL: {
|
||||
return TRI_FnvHashBlock(hash, "null", 4); // strlen("null")
|
||||
return HashBlock(hash, "null", 4); // strlen("null")
|
||||
}
|
||||
|
||||
case TRI_JSON_BOOLEAN: {
|
||||
if (object->_value._boolean) {
|
||||
return TRI_FnvHashBlock(hash, "true", 4); // strlen("true")
|
||||
return HashBlock(hash, "true", 4); // strlen("true")
|
||||
}
|
||||
else {
|
||||
return TRI_FnvHashBlock(hash, "false", 5); // strlen("true")
|
||||
return HashBlock(hash, "false", 5); // strlen("true")
|
||||
}
|
||||
}
|
||||
|
||||
case TRI_JSON_NUMBER: {
|
||||
return TRI_FnvHashBlock(hash, (char const*) &(object->_value._number),
|
||||
sizeof(object->_value._number));
|
||||
return HashBlock(hash, (char const*) &(object->_value._number), sizeof(object->_value._number));
|
||||
}
|
||||
|
||||
case TRI_JSON_STRING:
|
||||
case TRI_JSON_STRING_REFERENCE: {
|
||||
return TRI_FnvHashBlock(hash, object->_value._string.data,
|
||||
object->_value._string.length);
|
||||
return HashBlock(hash,
|
||||
object->_value._string.data,
|
||||
object->_value._string.length);
|
||||
}
|
||||
|
||||
case TRI_JSON_ARRAY: {
|
||||
hash = TRI_FnvHashBlock(hash, "array", 5); // strlen("array")
|
||||
hash = HashBlock(hash, "array", 5); // strlen("array")
|
||||
n = object->_value._objects._length;
|
||||
tmphash = hash;
|
||||
for (i = 0; i < n; i += 2) {
|
||||
|
@ -827,7 +846,7 @@ static uint64_t HashJsonRecursive (uint64_t hash, TRI_json_t const* object) {
|
|||
}
|
||||
|
||||
case TRI_JSON_LIST: {
|
||||
hash = TRI_FnvHashBlock(hash, "list", 4); // strlen("list")
|
||||
hash = HashBlock(hash, "list", 4); // strlen("list")
|
||||
n = object->_value._objects._length;
|
||||
for (i = 0; i < n; ++i) {
|
||||
subjson = (const TRI_json_t*) TRI_AtVector(&object->_value._objects, i);
|
||||
|
|
|
@ -78,7 +78,7 @@ static const uint64_t Primes[251] = {
|
|||
/// @brief return a prime number not lower than value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
uint64_t TRI_NextPrime (uint64_t value) {
|
||||
uint64_t TRI_NearPrime (uint64_t value) {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < sizeof(Primes); ++i) {
|
||||
|
|
|
@ -42,7 +42,7 @@ extern "C" {
|
|||
/// @brief return a prime number not lower than value
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
uint64_t TRI_NextPrime (uint64_t);
|
||||
uint64_t TRI_NearPrime (uint64_t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -75,6 +75,7 @@ add_library(
|
|||
BasicsC/csv.c
|
||||
BasicsC/debugging.c
|
||||
BasicsC/error.c
|
||||
BasicsC/fasthash.c
|
||||
BasicsC/files.c
|
||||
BasicsC/hashes.c
|
||||
BasicsC/init.c
|
||||
|
@ -85,6 +86,7 @@ add_library(
|
|||
BasicsC/memory.c
|
||||
BasicsC/mersenne.c
|
||||
BasicsC/mimetypes.c
|
||||
BasicsC/prime-numbers.c
|
||||
BasicsC/process-utils.c
|
||||
BasicsC/random.c
|
||||
BasicsC/skip-list.c
|
||||
|
@ -99,6 +101,7 @@ add_library(
|
|||
BasicsC/voc-errors.c
|
||||
BasicsC/voc-mimetypes.c
|
||||
BasicsC/tri-zip.c
|
||||
BasicsC/xxhash.c
|
||||
JsonParser/json-parser.c
|
||||
ProgramOptions/program-options.c
|
||||
Rest/AnyServer.cpp
|
||||
|
|
Loading…
Reference in New Issue