Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
Squashed 'deps/ccommon/' changes from b1babb2..9264bbb
Browse files Browse the repository at this point in the history
9264bbb Zero byte (twitter#147) (emergency fix needed for pelikan)
d4002d7 simplify cc_print_int64 (twitter#146)
b164fcf Clean-up hash functions and introduce MurmurHash3 (twitter#145)

git-subtree-dir: deps/ccommon
git-subtree-split: 9264bbb
  • Loading branch information
Yao Yue committed Apr 2, 2017
1 parent e7957bd commit de0fc63
Show file tree
Hide file tree
Showing 11 changed files with 595 additions and 557 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ matrix:
osx_image: xcode7.1
env: C_COMPILER=clang

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


before_install:
Expand Down
2 changes: 1 addition & 1 deletion 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 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 include/cc_lookup3.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/cc_hash.h → include/hash/cc_lookup3.h
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 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 );
11 changes: 5 additions & 6 deletions src/cc_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ cc_print_int64_unsafe(char *buf, int64_t n)
}

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

return (n < 0) ? d + 1 : d;
return d + (n < 0);
}

size_t
Expand All @@ -86,19 +86,18 @@ cc_print_int64(char *buf, size_t size, int64_t n)
size_t d;
uint64_t ab = abs_int64(n);

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

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

_print_uint64(buf, d, n);

return (n < 0) ? d + 1 : d;
return d + (n < 0);
}

size_t
Expand Down
2 changes: 1 addition & 1 deletion 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

0 comments on commit de0fc63

Please sign in to comment.