Skip to content

Commit

Permalink
Ported Coda Hale's Golang HdrHistogram to C
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhill committed May 31, 2018
1 parent f26b9b2 commit 7f602c2
Show file tree
Hide file tree
Showing 8 changed files with 943 additions and 0 deletions.
27 changes: 27 additions & 0 deletions LICENSE.hdrhistogram
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
This license covers src/rdhdrhistogram.c which is a C port of
Coda Hale's Golang HdrHistogram https://github.com/codahale/hdrhistogram
at revision 3a0bb77429bd3a61596f5e8a3172445844342120

-----------------------------------------------------------------------------

The MIT License (MIT)

Copyright (c) 2014 Coda Hale

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE
31 changes: 31 additions & 0 deletions LICENSES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,37 @@ LICENSE.crc32c
*/


LICENSE.hdrhistogram
--------------------------------------------------------------
This license covers src/rdhdrhistogram.c which is a C port of
Coda Hale's Golang HdrHistogram https://github.com/codahale/hdrhistogram
at revision 3a0bb77429bd3a61596f5e8a3172445844342120

-----------------------------------------------------------------------------

The MIT License (MIT)

Copyright (c) 2014 Coda Hale

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE


LICENSE.lz4
--------------------------------------------------------------
src/xxhash.[ch] src/lz4*.[ch]: [email protected]:lz4/lz4.git e2827775ee80d2ef985858727575df31fc60f1f3
Expand Down
5 changes: 5 additions & 0 deletions configure.librdkafka
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ void foo (void) {
"#include <zlib.h>"
mkl_lib_check "libcrypto" "" disable CC "-lcrypto"

if mkl_lib_check "libm" "" disable CC "-lm" \
"#include <math.h>"; then
mkl_allvar_set WITH_HDRHISTOGRAM WITH_HDRHISTOGRAM y
fi

if [[ "$ENABLE_LZ4_EXT" == "y" ]]; then
mkl_lib_check --static=-llz4 "liblz4" "WITH_LZ4_EXT" disable CC "-llz4" \
"#include <lz4frame.h>"
Expand Down
1 change: 1 addition & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SRCS_$(WITH_SASL_CYRUS) += rdkafka_sasl_cyrus.c
SRCS_$(WITH_SASL_SCRAM) += rdkafka_sasl_scram.c
SRCS_$(WITH_SNAPPY) += snappy.c
SRCS_$(WITH_ZLIB) += rdgz.c
SRCS_$(WITH_HDRHISTOGRAM) += rdhdrhistogram.c

SRCS_LZ4 = xxhash.c
ifneq ($(WITH_LZ4_EXT), y)
Expand Down
67 changes: 67 additions & 0 deletions src/rdfloat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* librdkafka - Apache Kafka C library
*
* Copyright (c) 2012-2018, Magnus Edenhill
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once


/**
* rd_dbl_eq0(a,b,prec)
* Check two doubles for equality with the specified precision.
* Use this instead of != and == for all floats/doubles.
* More info:
* http://docs.sun.com/source/806-3568/ncg_goldberg.html
*/
static inline int rd_dbl_eq0 (double a, double b, double prec) RD_UNUSED;
static inline int rd_dbl_eq0 (double a, double b, double prec) {
return fabs(a - b) < prec;
}

/* A default 'good' double-equality precision value.
* This rather timid epsilon value is useful for tenths, hundreths,
* and thousands parts, but not anything more precis than that.
* If a higher precision is needed, use dbl_eq0 and dbl_eq0 directly
* and specify your own precision. */
#define RD_DBL_EPSILON 0.00001

/**
* rd_dbl_eq(a,b)
* Same as rd_dbl_eq0() above but with a predefined 'good' precision.
*/
#define rd_dbl_eq(a,b) rd_dbl_eq0(a,b,RD_DBL_EPSILON)

/**
* rd_dbl_ne(a,b)
* Same as rd_dbl_eq() above but with reversed logic: not-equal.
*/
#define rd_dbl_ne(a,b) (!rd_dbl_eq0(a,b,RD_DBL_EPSILON))

/**
* rd_dbl_zero(a)
* Checks if the double `a' is zero (or close enough).
*/
#define rd_dbl_zero(a) rd_dbl_eq0(a,0.0,RD_DBL_EPSILON)
Loading

0 comments on commit 7f602c2

Please sign in to comment.