source: git/omalloc/omList.h @ 341696

spielwiese
Last change on this file since 341696 was 341696, checked in by Hans Schönemann <hannes@…>, 14 years ago
Adding Id property to all files git-svn-id: file:///usr/local/Singular/svn/trunk@12231 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.5 KB
Line 
1/*******************************************************************
2 *  File:    omList.h
3 *  Purpose: declaration of routines for operations on linked lists
4 *  Author:  obachman (Olaf Bachmann)
5 *  Created: 11/99
6 *  Version: $Id$
7 *******************************************************************/
8
9#ifndef OM_LIST_H
10#define OM_LIST_H
11
12#define OM_LIST_OFFSET(ptr, name_of_offset_field) \
13  (ptr != NULL ? ((char*) &(ptr->name_of_offset_field)) - ((char*) ptr) : 0)
14
15/********************************************************************
16 *
17 * Primitve routines -- don't use directly, use om macros, instead
18 *
19 ********************************************************************/
20/* Returns the length of a memory list; assumes list has no cycles */
21int _omListLength(void* list, int next);
22/* Returns last non-NULL element of list; assumes list has no cycles */
23void* _omListLast(void* list, int next);
24/* Checks whether memory list has cycles: If yes, returns address of
25 * first element of list which is contained at least twice in memory
26 * list. If no, NULL is returned */
27void* _omListHasCycle(void* list, int next);
28/* returns addr, if addr is contained in memory list
29 * 0, otherwise */
30void* _omIsOnList(void* list, int next, void* addr);
31/* Removes addr from list, if contained in it and returns new list */
32void* _omRemoveFromList(void* list, int next, void* addr);
33/*
34 * The following cast list->long_field to a pointer to  unsigned long
35 */
36/* Find element with that value in list and return it, if found (else NULL) */
37void* _omFindInList(void* list, int next, int long_field,
38                    unsigned long what);
39/*
40 * The following assume that list is ordered increasingly w.r.t. long_field
41 */
42/* Finds element in sorted list */
43void* _omFindInSortedList(void* list, int next, int long_field,
44                          unsigned long what);
45/* Remove element with that value from list and return new list */
46void* _omRemoveFromSortedList(void* list,int next,int long_field,
47                                  void* addr);
48/* Inserts addr at the right place, returns list assumes addr != NULL */
49void* _omInsertInSortedList(void* list, int next, int long_field,
50                            void* addr);
51#ifndef OM_NDEBUG
52/* Check whether list is ok, i.e. whether addr of lists are aligned and in valid range */
53omError_t _omCheckList(void* list, int next, int level, omError_t report, OM_FLR_DECL);
54/* like above, but also check that sorting is ok */
55omError_t _omCheckSortedList(void* list, int next, int long_field, int level, omError_t report, OM_FLR_DECL);
56#endif
57
58/********************************************************************
59 *
60 * The following routines assume that Next(list) == *((void**) list)
61 *
62 ********************************************************************/
63#define omListLength(ptr) \
64  _omListLength(ptr, 0)
65#define omListLast(ptr) \
66  _omListLast(ptr, 0)
67#define omListHasCycle(ptr) \
68  _omListHasCycle(ptr, 0)
69#define omIsOnList(ptr, addr) \
70  _omIsOnList(ptr, 0, addr)
71#define omRemoveFromList(ptr, addr) \
72  _omRemoveFromList(ptr, 0, addr)
73#define omFindInList(ptr, what, value) \
74  _omFindInList(ptr, 0, OM_LIST_OFFSET(ptr, what), (unsigned long) value)
75#define omInsertInSortedList(ptr, what, addr) \
76  _omInsertInSortedList(ptr, 0, OM_LIST_OFFSET(ptr, what), addr)
77#define omFindInSortedList(ptr, what, value) \
78  _omFindInSortedList(ptr, 0, OM_LIST_OFFSET(ptr, what), value)
79#define omRemoveFromSortedList(ptr, what, addr) \
80  _omRemoveFromSortedList(ptr, 0, OM_LIST_OFFSET(ptr, what), addr)
81#ifndef OM_NDEBUG
82#define omTestList(ptr, level) \
83  _omCheckList(ptr, 0, level, omError_NoError, OM_FLR)
84#define omCheckList(ptr, level, report, OM_FLR_VAL) \
85  _omCheckList(ptr, 0, level, report, OM_FLR_VAL)
86#define omCheckSortedList(ptr, what, level, report, OM_FLR_VAL) \
87  _omCheckSortedList(ptr, 0, OM_LIST_OFFSET(ptr, what), level, report, OM_FLR_VAL)
88#endif
89
90/********************************************************************
91 *
92 * The following routines have name of next field as argument
93 *
94 ********************************************************************/
95#define omGListLength(ptr, next) \
96  _omListLength(ptr, OM_LIST_OFFSET(ptr, next))
97#define omGListLast(ptr, next) \
98  _omListLast(ptr, OM_LIST_OFFSET(ptr, next))
99#define omGListHasCycle(ptr, next) \
100  _omListHasCycle(ptr, OM_LIST_OFFSET(ptr, next))
101#define omIsOnGList(ptr, next, addr) \
102  _omIsOnList(ptr, OM_LIST_OFFSET(ptr, next), addr)
103#define omRemoveFromGList(ptr, next, addr) \
104  _omRemoveFromList(ptr, OM_LIST_OFFSET(ptr, next), addr)
105#define omFindInGList(ptr, next, what, value) \
106  _omFindInList(ptr, OM_LIST_OFFSET(ptr, next), OM_LIST_OFFSET(ptr, what), (unsigned long) value)
107#define omInsertInSortedGList(ptr, next, what, addr) \
108  _omInsertInSortedList(ptr, OM_LIST_OFFSET(ptr, next), OM_LIST_OFFSET(ptr, what), addr)
109#define omFindInSortedGList(ptr, next, what, value) \
110  _omFindInSortedList(ptr, OM_LIST_OFFSET(ptr, next),OM_LIST_OFFSET(ptr,what),value)
111#define omRemoveFromSortedGList(ptr, next, what, addr) \
112  _omRemoveFromSortedList(ptr, OM_LIST_OFFSET(addr,next),OM_LIST_OFFSET(addr,what),addr)
113#ifndef OM_NDEBUG
114#define omTestGList(ptr, next, level) \
115 omCheckGList(ptr, next, level, omError_NoError, OM_FLR)
116#define omCheckGList(ptr, next, level, report, OM_FLR_VAL) \
117 _omCheckList(ptr, OM_LIST_OFFSET(ptr,next), level, report, OM_FLR_VAL)
118#define omCheckSortedGList(ptr, next, what, level, report, OM_FLR_VAL) \
119 _omCheckSortedList(ptr, OM_LIST_OFFSET(ptr,next), OM_LIST_OFFSET(ptr,what), level, report, OM_FLR_VAL)
120#else
121#define omTestGList(ptr, next, val) (omError_NoError)
122#endif
123
124#endif /* OM_LIST_H */
Note: See TracBrowser for help on using the repository browser.