Willy Tarreau | c218602 | 2009-10-26 19:48:54 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Elastic Binary Trees - exported generic functions |
Willy Tarreau | f3bfede | 2011-07-25 11:38:17 +0200 | [diff] [blame] | 3 | * Version 6.0.6 |
| 4 | * (C) 2002-2011 - Willy Tarreau <w@1wt.eu> |
Willy Tarreau | c218602 | 2009-10-26 19:48:54 +0100 | [diff] [blame] | 5 | * |
Willy Tarreau | f3bfede | 2011-07-25 11:38:17 +0200 | [diff] [blame] | 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation, version 2.1 |
| 9 | * exclusively. |
Willy Tarreau | c218602 | 2009-10-26 19:48:54 +0100 | [diff] [blame] | 10 | * |
Willy Tarreau | f3bfede | 2011-07-25 11:38:17 +0200 | [diff] [blame] | 11 | * This library is distributed in the hope that it will be useful, |
Willy Tarreau | c218602 | 2009-10-26 19:48:54 +0100 | [diff] [blame] | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Willy Tarreau | f3bfede | 2011-07-25 11:38:17 +0200 | [diff] [blame] | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
Willy Tarreau | c218602 | 2009-10-26 19:48:54 +0100 | [diff] [blame] | 15 | * |
Willy Tarreau | f3bfede | 2011-07-25 11:38:17 +0200 | [diff] [blame] | 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
Willy Tarreau | c218602 | 2009-10-26 19:48:54 +0100 | [diff] [blame] | 19 | */ |
| 20 | |
Willy Tarreau | 8d2b777 | 2020-05-27 10:58:19 +0200 | [diff] [blame] | 21 | #include <import/ebtree.h> |
Willy Tarreau | c218602 | 2009-10-26 19:48:54 +0100 | [diff] [blame] | 22 | |
| 23 | void eb_delete(struct eb_node *node) |
| 24 | { |
| 25 | __eb_delete(node); |
| 26 | } |
| 27 | |
| 28 | /* used by insertion primitives */ |
Willy Tarreau | 03e7853 | 2020-02-25 07:38:05 +0100 | [diff] [blame] | 29 | struct eb_node *eb_insert_dup(struct eb_node *sub, struct eb_node *new) |
Willy Tarreau | c218602 | 2009-10-26 19:48:54 +0100 | [diff] [blame] | 30 | { |
| 31 | return __eb_insert_dup(sub, new); |
| 32 | } |
Willy Tarreau | 853926a | 2020-06-16 11:10:53 +0200 | [diff] [blame] | 33 | |
| 34 | /* compares memory blocks m1 and m2 for up to <len> bytes. Immediately stops at |
| 35 | * the first non-matching byte. It returns 0 on full match, non-zero otherwise. |
| 36 | * One byte will always be checked so this must not be called with len==0. It |
| 37 | * takes 2+5cy/B on x86_64 and is ~29 bytes long. |
| 38 | */ |
| 39 | int eb_memcmp(const void *m1, const void *m2, size_t len) |
| 40 | { |
| 41 | const char *p1 = (const char *)m1 + len; |
| 42 | const char *p2 = (const char *)m2 + len; |
| 43 | ssize_t ofs = -len; |
| 44 | char diff; |
| 45 | |
| 46 | do { |
| 47 | diff = p1[ofs] - p2[ofs]; |
| 48 | } while (!diff && ++ofs); |
| 49 | return diff; |
| 50 | } |