📄 mmlist.h
字号:
/* $Id: mmlist.h,v 1.3 2003/01/08 20:57:46 mmondor Exp $ *//* * Copyright (C) 2000-2003, Matthew Mondor * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software written by Matthew Mondor. * 4. The name of Matthew Mondor may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY MATTHEW MONDOR ``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 MATTHEW MONDOR 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 MM_LIST_H#define MM_LIST_H#include <sys/types.h>#include <mmtypes.h>typedef struct node { struct node *prev, *next; struct bpage *page;} node;typedef struct bpage { struct node nod; struct bpool *pool; long used;} bpage;typedef struct list { struct node *top, *bottom; struct bpool *pool; long nodes;} list;typedef struct bpool { void * (*malloc)(size_t); void (*free)(void *); long maxpages, avgtotal, avgcnt; size_t nodesize, pagesize; struct list bpages, bfpages, bnodes; bool block;} bpool;/* Some macros to optimize operations */#define INITLIST(lst) do { \ (lst)->top = (lst)->bottom = NULL; \ (lst)->pool = NULL; \ (lst)->nodes = 0; \} while (0)#define UNLINKNODE(lst, nod) do { \ register node *prev = (nod)->prev, *next = (nod)->next; \ if (prev) prev->next = next; \ else (lst)->top = next; \ if (next) next->prev = prev; \ else (lst)->bottom = prev; \ (lst)->nodes--; \} while (0)#define APPENDNODE(lst, nod) do { \ register node *tmp = (lst)->bottom; \ if (tmp) { \ tmp->next = (nod); \ (nod)->prev = tmp; \ (nod)->next = NULL; \ (lst)->bottom = (nod); \ } else { \ (lst)->bottom = (lst)->top = (nod); \ (nod)->next = (nod)->prev = NULL; \ } \ (lst)->nodes++; \} while (0)#define INSERTNODE(lst, nod) do { \ register node *tmp = (lst)->top; \ if (tmp) { \ tmp->prev = (nod); \ (nod)->prev = NULL; \ (nod)->next = tmp; \ (lst)->top = (nod); \ } else { \ (lst)->top = (lst)->bottom = (nod); \ (nod)->next = (nod)->prev = NULL; \ } \ (lst)->nodes++; \} while (0)#define INSERTNODEAT(lst, atnode, nod) do { \ register node *prev = (atnode)->prev, *next = (atnode); \ (nod)->next = next; \ next->prev = (nod); \ if (prev) { \ prev->next = (nod); \ (nod)->prev = prev; \ } else { \ (lst)->top = (nod); \ (nod)->prev = NULL; \ } \ (lst)->nodes++; \} while (0)#define SWAPNODE(dst, src, nod, ins) do { \ register node *prev = (nod)->prev, *next = (nod)->next; \ if (prev) prev->next = next; \ else (src)->top = next; \ if (next) next->prev = prev; \ else (src)->bottom = prev; \ (src)->nodes--; \ if ((ins)) { \ if ((prev = (dst)->top)) { \ prev->prev = (nod); \ (nod)->prev = NULL; \ (nod)->next = prev; \ (dst)->top = (nod); \ } else { \ (dst)->top = (dst)->bottom = (nod); \ (nod)->next = (nod)->prev = NULL; \ } \ } else { \ if ((prev = (dst)->bottom)) { \ prev->next = (nod); \ (nod)->prev = prev; \ (nod)->next = NULL; \ (dst)->bottom = (nod); \ } else { \ (dst)->bottom = (dst)->top = (nod); \ (nod)->next = (nod)->prev = NULL; \ } \ } \ (dst)->nodes++; \} while (0)/* General allocation/free functions */list *openlist(void * (*)(size_t), void (*)(void *), size_t, size_t, long);list *blocklist(void * (*)(size_t), void (*)(void *), size_t, long);list *closelist(list *);node *allocnode(list *, bool);node *freenode(node *);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -