#include <List.h>
Public Member Functions | |
| ~BaseList () | |
| void | clear () |
| int | length () const |
| int | chunk () const |
| int | max () const |
| int | resize (int=0) |
| void | sort (list_cmp_func cmp_func) |
| int | MemoryAllocation () const |
Protected Member Functions | |
| BaseList (int=0) | |
| BaseList (BaseList &) | |
| void | insert (ent) |
| void | sortedinsert (ent, list_cmp_func cmp_func) |
| void | append (ent) |
| ent | remove (ent) |
| ent | remove_nth (int) |
| ent | get () |
| ent | last () |
| ent | is_member (ent) const |
| int | member_pos (ent) const |
| ent | replace (int, ent) |
| ent | operator[] (int i) const |
| void | operator= (BaseList &) |
Protected Attributes | |
| ent * | entry |
| int | chunk_size |
| int | max_entries |
| int | num_entries |
|
|
Definition at line 33 of file List.h. References clear().
00033 { clear(); }
|
|
|
Definition at line 13 of file List.cc. References chunk_size, DEFAULT_CHUNK_SIZE, ent, entry, max_entries, num_entries, safe_malloc(), and size.
00014 {
00015 chunk_size = DEFAULT_CHUNK_SIZE;
00016
00017 if ( size < 0 )
00018 {
00019 num_entries = max_entries = 0;
00020 entry = 0;
00021 }
00022 else
00023 {
00024 if ( size > 0 )
00025 chunk_size = size;
00026
00027 num_entries = 0;
00028 entry = (ent *) safe_malloc(chunk_size * sizeof(ent));
00029 max_entries = chunk_size;
00030 }
00031 }
|
|
|
Definition at line 34 of file List.cc. References chunk_size, ent, entry, max_entries, num_entries, and safe_malloc().
00035 {
00036 max_entries = b.max_entries;
00037 chunk_size = b.chunk_size;
00038 num_entries = b.num_entries;
00039
00040 if ( max_entries )
00041 entry = (ent *) safe_malloc(max_entries * sizeof(ent));
00042 else
00043 entry = 0;
00044
00045 for ( int i = 0; i < num_entries; ++i )
00046 entry[i] = b.entry[i];
00047 }
|
|
|
Definition at line 143 of file List.cc. References chunk_size, ent, entry, max_entries, num_entries, and resize().
00144 {
00145 if ( num_entries == max_entries )
00146 {
00147 resize(max_entries + chunk_size); // make more room
00148 chunk_size *= 2;
00149 }
00150
00151 entry[num_entries++] = a;
00152 }
|
|
|
Definition at line 37 of file List.h. References chunk_size.
00037 { return chunk_size; }
|
|
|
Definition at line 164 of file List.cc. References chunk_size, DEFAULT_CHUNK_SIZE, entry, max_entries, and num_entries. Referenced by ~BaseList().
00165 {
00166 if ( entry )
00167 {
00168 free(entry);
00169 entry = 0;
00170 }
00171
00172 num_entries = max_entries = 0;
00173 chunk_size = DEFAULT_CHUNK_SIZE;
00174 }
|
|
|
Definition at line 155 of file List.cc. References ent, entry, and num_entries.
00156 {
00157 if ( num_entries == 0 )
00158 return 0;
00159
00160 return entry[--num_entries];
00161 }
|
|
|
Definition at line 75 of file List.cc. References chunk_size, ent, entry, max_entries, num_entries, and resize().
00076 {
00077 if ( num_entries == max_entries )
00078 {
00079 resize(max_entries + chunk_size); // make more room
00080 chunk_size *= 2;
00081 }
00082
00083 for ( int i = num_entries; i > 0; --i )
00084 entry[i] = entry[i-1]; // move all pointers up one
00085
00086 ++num_entries;
00087 entry[0] = a;
00088 }
|
|
|
Definition at line 213 of file List.cc. References ent, entry, and length().
|
|
|
Definition at line 59 of file List.h. References ent, entry, and num_entries.
00060 { return entry[num_entries-1]; }
|
|
|
Definition at line 36 of file List.h. References num_entries. Referenced by is_member(), and member_pos().
00036 { return num_entries; }
|
|
|
Definition at line 38 of file List.h. References max_entries.
00038 { return max_entries; }
|
|
|
Definition at line 222 of file List.cc. References ent, entry, and length().
|
|
|
Definition at line 43 of file List.h. References ent, max_entries, pad_size(), and padded_sizeof.
00044 { return padded_sizeof(*this) + pad_size(max_entries * sizeof(ent)); }
|
|
|
Definition at line 54 of file List.cc. References chunk_size, ent, entry, max_entries, num_entries, and safe_malloc().
00055 {
00056 if ( this == &b )
00057 return; // i.e., this already equals itself
00058
00059 if ( entry )
00060 free(entry);
00061
00062 max_entries = b.max_entries;
00063 chunk_size = b.chunk_size;
00064 num_entries = b.num_entries;
00065
00066 if ( max_entries )
00067 entry = (ent *) safe_malloc(max_entries * sizeof(ent));
00068 else
00069 entry = 0;
00070
00071 for ( int i = 0; i < num_entries; ++i )
00072 entry[i] = b.entry[i];
00073 }
|
|
|
Definition at line 71 of file List.h. References ent, entry, and num_entries.
00072 {
00073 #ifdef SAFE_LISTS
00074 if ( i < 0 || i > num_entries-1 )
00075 return 0;
00076 else
00077 #endif
00078 return entry[i];
00079 }
|
|
|
Definition at line 119 of file List.cc. References ent, entry, num_entries, and remove_nth().
00120 {
00121 int i;
00122 for ( i = 0; i < num_entries && a != entry[i]; ++i )
00123 ;
00124
00125 return remove_nth(i);
00126 }
|
|
|
Definition at line 128 of file List.cc. References ent, entry, and num_entries. Referenced by remove().
00129 {
00130 if ( n < 0 || n >= num_entries )
00131 return 0;
00132
00133 ent old_ent = entry[n];
00134 --num_entries;
00135
00136 for ( ; n < num_entries; ++n )
00137 entry[n] = entry[n+1];
00138
00139 entry[n] = 0; // for debugging
00140 return old_ent;
00141 }
|
|
||||||||||||
|
Definition at line 176 of file List.cc. References ent, entry, num_entries, and resize().
00177 {
00178 if ( ent_index < 0 )
00179 return 0;
00180
00181 ent old_ent;
00182
00183 if ( ent_index > num_entries-1 )
00184 {
00185 resize(ent_index+1);
00186 old_ent = 0;
00187 }
00188 else
00189 old_ent = entry[ent_index];
00190
00191 entry[ent_index] = new_ent;
00192
00193 return old_ent;
00194 }
|
|
|
Definition at line 196 of file List.cc. References ent, entry, max_entries, num_entries, and safe_realloc(). Referenced by append(), insert(), replace(), and sortedinsert().
00197 {
00198 if ( new_size < num_entries )
00199 new_size = num_entries; // do not lose any entries
00200
00201 if ( new_size != max_entries )
00202 {
00203 entry = (ent*) safe_realloc((void*) entry, sizeof(ent) * new_size);
00204 if ( entry )
00205 max_entries = new_size;
00206 else
00207 max_entries = 0;
00208 }
00209
00210 return max_entries;
00211 }
|
|
|
Definition at line 49 of file List.cc. References ent, entry, list_cmp_func, and num_entries.
00050 {
00051 qsort(entry, num_entries, sizeof(ent), cmp_func);
00052 }
|
|
||||||||||||
|
Definition at line 92 of file List.cc. References chunk_size, ent, entry, list_cmp_func, max_entries, num_entries, and resize().
00093 {
00094 // We optimize for the case that the new element is
00095 // larger than most of the current entries.
00096
00097 // First append element.
00098 if ( num_entries == max_entries )
00099 {
00100 resize(max_entries + chunk_size);
00101 chunk_size *= 2;
00102 }
00103
00104 entry[num_entries++] = a;
00105
00106 // Then move it to the correct place.
00107 ent tmp;
00108 for ( int i = num_entries - 1; i > 0; --i )
00109 {
00110 if ( cmp_func(entry[i],entry[i-1]) <= 0 )
00111 break;
00112
00113 tmp = entry[i];
00114 entry[i] = entry[i-1];
00115 entry[i-1] = tmp;
00116 }
00117 }
|
|
|
Definition at line 84 of file List.h. Referenced by append(), BaseList(), chunk(), clear(), insert(), operator=(), and sortedinsert(). |
|
|
Definition at line 83 of file List.h. Referenced by append(), BaseList(), clear(), get(), insert(), is_member(), last(), member_pos(), operator=(), operator[](), remove(), remove_nth(), replace(), resize(), sort(), and sortedinsert(). |
|
|
Definition at line 85 of file List.h. Referenced by append(), BaseList(), clear(), insert(), max(), MemoryAllocation(), operator=(), resize(), and sortedinsert(). |
|
|
Definition at line 86 of file List.h. Referenced by append(), BaseList(), clear(), get(), insert(), last(), length(), operator=(), operator[](), remove(), remove_nth(), replace(), resize(), sort(), and sortedinsert(). |
1.3.5