Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redis protocol: tokenizer, hash and zset #146

Merged
merged 23 commits into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ matrix:

# clang 3.7 on osx
- os: osx
osx_image: xcode7.1
osx_image: xcode7.3
env: C_COMPILER=clang

# # clang 4.2 on osx
# - os: osx
# osx_image: xcode8.2
# env: C_COMPILER=clang


before_install:
# for osx: 0. update brew; 1. install cmake if missing; 2. (gcc) unlink pre-installed gcc; 3. (gcc) install desired version of gcc
Expand All @@ -93,4 +98,5 @@ script:
- cmake ..
- make -j
- make check
- egrep -r ":F:|:E:" . || true
- cd ../test/integration && python test_twemcache.py
6 changes: 6 additions & 0 deletions deps/ccommon/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ matrix:
osx_image: xcode7.1
env: C_COMPILER=clang

# # clang 4.2 on osx
# - os: osx
# osx_image: xcode8.2
# env: C_COMPILER=clang


before_install:
# for osx: 0. update brew; 1. install cmake if missing; 2. (gcc) unlink pre-installed gcc; 3. (gcc) install desired version of gcc
Expand All @@ -93,3 +98,4 @@ script:
- cmake ..
- make -j
- make check
- egrep -r ":F:|:E:" . || true
2 changes: 1 addition & 1 deletion deps/ccommon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ endif()

# version info
set(${PROJECT_NAME}_VERSION_MAJOR 1)
set(${PROJECT_NAME}_VERSION_MINOR 1)
set(${PROJECT_NAME}_VERSION_MINOR 2)
set(${PROJECT_NAME}_VERSION_PATCH 0)
set(${PROJECT_NAME}_VERSION
${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}
Expand Down
4 changes: 4 additions & 0 deletions deps/ccommon/include/buffer/cc_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ buf_read(char *dst, struct buf *src, uint32_t count)
static inline uint32_t
buf_write(struct buf *dst, char *src, uint32_t count)
{
if (count == 0) {
return 0;
}

ASSERT(dst != NULL && src != NULL);

uint32_t len = MIN(buf_wsize(dst), count);
Expand Down
38 changes: 0 additions & 38 deletions deps/ccommon/include/cc_lookup3.h

This file was deleted.

3 changes: 3 additions & 0 deletions deps/ccommon/include/cc_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ extern "C" {

/* behavior undefined if there isn't enough space in buf */
size_t cc_print_uint64_unsafe(char *buf, uint64_t n);
size_t cc_print_int64_unsafe(char *buf, int64_t n);

size_t cc_print_uint64(char *buf, size_t size, uint64_t n);
size_t cc_print_int64(char *buf, size_t size, int64_t n);

size_t _scnprintf(char *buf, size_t size, const char *fmt, ...);
size_t _vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
Expand Down
4 changes: 4 additions & 0 deletions deps/ccommon/include/cc_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ extern "C" {
* # define UINT16_MAX (65535)
* # define UINT32_MAX (4294967295U)
* # define UINT64_MAX (__UINT64_C(18446744073709551615))
*
* # define INT64_MIN -9223372036854775808LL
*/
#define CC_UINT8_MAXLEN (3 + 1)
#define CC_UINT16_MAXLEN (5 + 1)
#define CC_UINT32_MAXLEN (10 + 1)
#define CC_UINT64_MAXLEN (20 + 1)
#define CC_UINTMAX_MAXLEN CC_UINT64_MAXLEN

#define CC_INT64_MAXLEN (1 + 19 + 1)

/* alignment */
/* Make data 'd' or pointer 'p', n-byte aligned, where n is a power of 2 */
#define CC_ALIGNMENT sizeof(unsigned long) /* platform word */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern "C" {
#include <stdint.h>
#include <stdlib.h>

uint32_t hash(const void *key, size_t length, const uint32_t initval);
uint32_t hash_lookup3(const void *key, size_t length, const uint32_t initval);

#ifdef __cplusplus
}
Expand Down
39 changes: 39 additions & 0 deletions deps/ccommon/include/hash/cc_murmur3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* ccommon - a cache common library.
* Copyright (C) 2013 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* The cc_murmur3.[ch] are adapated from the canonical implementation of
* MurmurHash3 by Austin Appleby, released as part of SMHasher:
* https://github.com/aappleby/smhasher
*
* Changes include renaming fuctions, removing MSVC-related code, adding "static"
* keyword to local-scope functions according to C language spec (original code is
* in C++), to better fit them into the scope and style of ccommon
*
* The actual implementation is untouched.
*/

#pragma once

#include <stdint.h>


void hash_murmur3_32 ( const void * key, int len, uint32_t seed, void * out );

void hash_murmur3_128_x86 ( const void * key, int len, uint32_t seed, void * out );

void hash_murmur3_128_x64 ( const void * key, int len, uint32_t seed, void * out );
39 changes: 39 additions & 0 deletions deps/ccommon/src/cc_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* implementation as a reference (folly/Conv.h)
*/

/* use our own macro instead of llabs() to make sure it works with INT64_MIN */
#define abs_int64(_x) ((_x) >= 0 ? (_x) : -(_x))

static inline void
_print_uint64(char *buf, size_t d, uint64_t n)
{
Expand All @@ -46,6 +49,22 @@ cc_print_uint64_unsafe(char *buf, uint64_t n)
return d;
}

size_t
cc_print_int64_unsafe(char *buf, int64_t n)
{
size_t d;
uint64_t ab = abs_int64(n);

if (n < 0) {
*buf++ = '-';
}

d = digits(ab);
_print_uint64(buf, d, ab);

return d + (n < 0);
}

size_t
cc_print_uint64(char *buf, size_t size, uint64_t n)
{
Expand All @@ -61,6 +80,26 @@ cc_print_uint64(char *buf, size_t size, uint64_t n)
return d;
}

size_t
cc_print_int64(char *buf, size_t size, int64_t n)
{
size_t d;
uint64_t ab = abs_int64(n);

d = digits(ab);
if (size < d + (n < 0)) {
return 0;
}

if (n < 0) {
*buf++ = '-';
}

_print_uint64(buf, d, n);

return d + (n < 0);
}

size_t
_vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
{
Expand Down
2 changes: 1 addition & 1 deletion deps/ccommon/src/hash/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set(SOURCE
${SOURCE}
hash/cc_hash.c
hash/cc_lookup3.c
hash/cc_murmur3.c
PARENT_SCOPE)
Loading