00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "sparse.h"
00013
00014 #include "util_hack.h"
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #define sorted_insert(type, first, last, count, next, prev, value, newval, e) \
00034 if (last == 0) { \
00035 e->value = newval; \
00036 first = e; \
00037 last = e; \
00038 e->next = 0; \
00039 e->prev = 0; \
00040 count++; \
00041 } else if (last->value < newval) { \
00042 e->value = newval; \
00043 last->next = e; \
00044 e->prev = last; \
00045 last = e; \
00046 e->next = 0; \
00047 count++; \
00048 } else if (first->value > newval) { \
00049 e->value = newval; \
00050 first->prev = e; \
00051 e->next = first; \
00052 first = e; \
00053 e->prev = 0; \
00054 count++; \
00055 } else { \
00056 type *p; \
00057 for(p = first; p->value < newval; p = p->next) \
00058 ; \
00059 if (p->value > newval) { \
00060 e->value = newval; \
00061 p = p->prev; \
00062 p->next->prev = e; \
00063 e->next = p->next; \
00064 p->next = e; \
00065 e->prev = p; \
00066 count++; \
00067 } else { \
00068 e = p; \
00069 } \
00070 }
00071
00072
00073
00074
00075
00076 #define dll_unlink(p, first, last, next, prev, count) { \
00077 if (p->prev == 0) { \
00078 first = p->next; \
00079 } else { \
00080 p->prev->next = p->next; \
00081 } \
00082 if (p->next == 0) { \
00083 last = p->prev; \
00084 } else { \
00085 p->next->prev = p->prev; \
00086 } \
00087 count--; \
00088 }
00089
00090
00091 #ifdef FAST_AND_LOOSE
00092 extern sm_element *sm_element_freelist;
00093 extern sm_row *sm_row_freelist;
00094 extern sm_col *sm_col_freelist;
00095
00096 #define sm_element_alloc(newobj) \
00097 if (sm_element_freelist == NIL(sm_element)) { \
00098 newobj = ALLOC(sm_element, 1); \
00099 } else { \
00100 newobj = sm_element_freelist; \
00101 sm_element_freelist = sm_element_freelist->next_col; \
00102 } \
00103 newobj->user_word = NIL(char); \
00104
00105 #define sm_element_free(e) \
00106 (e->next_col = sm_element_freelist, sm_element_freelist = e)
00107
00108 #else
00109
00110 #define sm_element_alloc(newobj) \
00111 newobj = ALLOC(sm_element, 1); \
00112 newobj->user_word = NIL(char);
00113 #define sm_element_free(e) \
00114 FREE(e)
00115 #endif
00116
00117
00118 extern void sm_row_remove_element();
00119 extern void sm_col_remove_element();
00120
00121