From b8db533bef3a90b44777488ef2636a346ffc0773 Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Sat, 30 Jan 2021 13:03:08 +0000 Subject: [PATCH 1/2] [add] Add the ability to change allocator at compile time --- src/td_malloc.h | 20 ++++++++++++++++++++ src/tdigest.c | 10 ++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/td_malloc.h diff --git a/src/td_malloc.h b/src/td_malloc.h new file mode 100644 index 0000000..10da29d --- /dev/null +++ b/src/td_malloc.h @@ -0,0 +1,20 @@ +/** + * Adaptive histogram based on something like streaming k-means crossed with Q-digest. + * The implementation is a direct descendent of MergingDigest + * https://github.com/tdunning/t-digest/ + * + * Copyright (c) 2021 Filipe Oliveira, All rights reserved. + * + * Allocator selection. + * + * This file is used in order to change the t-digest allocator at compile time. + * Just define the following defines to what you want to use. Also add + * the include of your alternate allocator if needed (not needed in order + * to use the default libc allocator). */ + +#ifndef TD_ALLOC_H +#define TD_ALLOC_H +#define __td_malloc malloc +#define __td_realloc realloc +#define __td_free free +#endif \ No newline at end of file diff --git a/src/tdigest.c b/src/tdigest.c index 6bb2ca7..824c072 100644 --- a/src/tdigest.c +++ b/src/tdigest.c @@ -4,6 +4,12 @@ #include #include "tdigest.h" +#ifndef TD_MALLOC_INCLUDE +#define TD_MALLOC_INCLUDE "td_malloc.h" +#endif + +#include TD_MALLOC_INCLUDE + void bbzero(void *to, size_t count) { memset(to, 0, count); } static bool is_very_small(double val) { return !(val > .000000001 || val < -.000000001); } @@ -56,10 +62,10 @@ static td_histogram_t *td_init(double compression, size_t buf_size, char *buf) { td_histogram_t *td_new(double compression) { size_t memsize = td_required_buf_size(compression); - return td_init(compression, memsize, (char *)(malloc(memsize))); + return td_init(compression, memsize, (char *)(__td_malloc(memsize))); } -void td_free(td_histogram_t *h) { free((void *)(h)); } +void td_free(td_histogram_t *h) { __td_free((void *)(h)); } void td_merge(td_histogram_t *into, td_histogram_t *from) { td_compress(into); From f5abcefa13afab8d900072b59d196a53b88a43b5 Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Sat, 30 Jan 2021 13:07:11 +0000 Subject: [PATCH 2/2] [add] added RL license year --- src/td_malloc.h | 2 +- src/tdigest.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/td_malloc.h b/src/td_malloc.h index 10da29d..fa76fc8 100644 --- a/src/td_malloc.h +++ b/src/td_malloc.h @@ -3,7 +3,7 @@ * The implementation is a direct descendent of MergingDigest * https://github.com/tdunning/t-digest/ * - * Copyright (c) 2021 Filipe Oliveira, All rights reserved. + * Copyright (c) 2021 Redis Labs, All rights reserved. * * Allocator selection. * diff --git a/src/tdigest.h b/src/tdigest.h index 8dc7fce..ec44862 100644 --- a/src/tdigest.h +++ b/src/tdigest.h @@ -6,6 +6,7 @@ * The implementation is a direct descendent of MergingDigest * https://github.com/tdunning/t-digest/ * + * Copyright (c) 2021 Redis Labs, All rights reserved. * Copyright (c) 2018 Andrew Werner, All rights reserved. * * The special characteristics of this algorithm are: