Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
condret committed Oct 20, 2021
1 parent 8bd0a65 commit cd8a426
Show file tree
Hide file tree
Showing 4 changed files with 434 additions and 1 deletion.
1 change: 1 addition & 0 deletions libr/include/r_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int gettimeofday (struct timeval* p, void* tz);
#include "r_util/r_signal.h"
#include "r_util/r_alloc.h"
#include "r_util/r_rbtree.h"
#include "r_util/r_new_rbtree.h"
#include "r_util/r_intervaltree.h"
#include "r_util/r_big.h"
#include "r_util/r_base64.h"
Expand Down
73 changes: 73 additions & 0 deletions libr/include/r_util/r_new_rbtree.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
BSD 2-Clause License
Copyright (c) 2018, lynnl
Cleaned up and refactored for r2 in 2021: condret
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* 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 HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 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.
*/

#ifndef RBTREE_H
#define RBTREE_H

#include <r_util.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct r_rbtree_node {
struct r_rbtree_node *link[2];
struct r_rbtree_node *parent;
ut32 red;
void *data;
} RRBNode;

typedef int (*RRBComparator) (void *incoming, void *in, void *user);
typedef void (*RRBFree) (void *data);

typedef struct r_rbtree_t {
RRBNode *root;
size_t size;
RRBFree free;
} RRBTree;

R_API RBTree *r_rbtree_new(RRBFree freefn);
R_API void r_rbtree_clear(RRBTree *tree);
R_API void r_rbtree_free(RRBTree *tree);
R_API RRBNode *r_rbtree_find_node(RRBTree *tree, void *data, RRBComparator cmp, void *user);
R_API void *r_rbtree_find(RRBTree *tree, void *data, RRBComparator cmp, void *user);
R_API bool r_rbtree_insert(RRBTree *tree, void *data, RRBComparator cmp, void *user);
R_API bool r_rbtree_delete(RRBTree *tree, void *data, RRBComparator cmp, void *user);
R_API RRBNode *r_rbtree_first_node(RRBTree *tree);
R_API RRBNode *r_rbtree_last_node(RRBTree *tree);
R_API RRBNode *r_rbnode_next(RRBNode *node);
R_API RRBNode *r_rbnode_prev(RRBNode *node);

#ifdef __cplusplus
}
#endif

#endif /* RBTREE_H */
2 changes: 1 addition & 1 deletion libr/util/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ OBJS+=utf8.o utf16.o utf32.o strbuf.o lib.o name.o spaces.o signal.o syscmd.o
OBJS+=udiff.o bdiff.o stack.o queue.o tree.o idpool.o assert.o
OBJS+=punycode.o pkcs7.o x509.o asn1.o astr.o json_parser.o json_indent.o skiplist.o
OBJS+=pj.o rbtree.o intervaltree.o qrcode.o vector.o skyline.o str_constpool.o str_trim.o
OBJS+=ascii_table.o protobuf.o graph_drawable.o axml.o sstext.o
OBJS+=ascii_table.o protobuf.o graph_drawable.o axml.o sstext.o new_rbtree.o

ifeq (${HAVE_GPERF},1)
OBJS+=d/ascii.o
Expand Down

0 comments on commit cd8a426

Please sign in to comment.