splay tree minor fixes + header;

This commit is contained in:
Alexander Vdolainen 2026-10-12 15:44:22 +03:00
parent 5d57fbcdfd
commit a7645b813c
2 changed files with 43 additions and 9 deletions

View File

@ -1,13 +1,28 @@
/* splay tree implementation */ /*
* this is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* this is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.";
*
* (c) Alexander Vdolainen 2007, 2026 <alex@vapaa.xyz>
* subrelay: a minimalistic maillist server based on external IMAPs/SMTPs
*
* splay.h: splay tree implementation
*
*/
#ifndef __SPLAY_H__ #ifndef __SPLAY_H__
#define __SPLAY_H__ #define __SPLAY_H__
#include <stdint.h> #include <stdint.h>
#define tree_root_priv(T) ((T)->splay_sentinel.splay_left)
#define tree_null_priv(L) (&(L)->splay_sentinel)
#define TREE_DEPTH_MAX 64
typedef long (*splay_compare_t)(const void*, const void*); typedef long (*splay_compare_t)(const void*, const void*);
typedef struct __splay_node_t { typedef struct __splay_node_t {
@ -20,7 +35,6 @@ typedef struct __splay_node_t {
typedef struct __splay_t { typedef struct __splay_t {
uint64_t nodecount; uint64_t nodecount;
uint64_t maxcount;
splay_node_t splay_sentinel; splay_node_t splay_sentinel;
splay_compare_t splay_compare; splay_compare_t splay_compare;
void *splay_context; void *splay_context;

View File

@ -1,4 +1,23 @@
/* splay tree implementation */ /*
* this is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* this is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.";
*
* (c) Alexander Vdolainen 2007, 2026 <alex@vapaa.xyz>
* subrelay: a minimalistic maillist server based on external IMAPs/SMTPs
*
* splay.c: splay tree implementation
*
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -7,6 +26,9 @@
#include <ilib/splay.h> #include <ilib/splay.h>
#define tree_root_priv(T) ((T)->splay_sentinel.splay_left)
#define tree_null_priv(L) (&(L)->splay_sentinel)
static void splay_node(splay_t *, splay_node_t *); static void splay_node(splay_t *, splay_node_t *);
static void tree_rotate_left(splay_node_t *, splay_node_t *); static void tree_rotate_left(splay_node_t *, splay_node_t *);
static void tree_rotate_right(splay_node_t *, splay_node_t *); static void tree_rotate_right(splay_node_t *, splay_node_t *);
@ -21,8 +43,6 @@ int splay_init(splay_t *sp, splay_compare_t cmp_fu)
memset(sp, 0, sizeof(splay_t)); memset(sp, 0, sizeof(splay_t));
/* FIXME: do better maxcount */
sp->maxcount = 65535;
sp->splay_compare = cmp_fu; sp->splay_compare = cmp_fu;
/* tree init */ /* tree init */