cgma
|
#include <DLIList.hpp>
Public Types | |
typedef std::vector< X >::reference | reference |
typedef vector_const_reference_type< X > ::type | const_reference |
typedef std::vector< X >::pointer | pointer |
typedef std::vector< X > ::const_pointer | const_pointer |
typedef std::vector< X > ::const_iterator | const_iterator |
typedef std::vector< X >::iterator | iterator |
typedef std::vector< X > ::value_type | value_type |
typedef int(* | SortFunction )(X &a, X &b) |
A function which determines the relative order of objects. | |
Public Member Functions | |
DLIList (int size=0) | |
Constructor: Create a list, allocating enough storage for size elements. | |
DLIList (const DLIList< X > &from) | |
Copy constructor. | |
DLIList (const std::vector< X > &from) | |
Copy constructor for std::vector. | |
~DLIList () | |
Destructor: Free all resources used by this list. | |
iterator | begin () |
return a begin iterator | |
const_iterator | begin () const |
return begin iterator | |
iterator | end () |
return end iterator | |
const_iterator | end () const |
return end iterator | |
void | step () |
Move the pointer to the next element in the list. | |
void | step (int n) |
Move the pointer n positions forward in the list. | |
void | back () |
Move the pointer to the previous element in the list. | |
void | back (int n) |
Move the pointer n positions backward in the list. | |
void | reset () |
Set the pointer to the beginning of the list. | |
void | last () |
Set the pointer to the end of the list. | |
void | clean_out () |
Delete all elements in the list. | |
void | shrink (int k) |
Reduces the size of the list by k. | |
CubitBoolean | is_at_beginning () const |
Returns CUBIT_TRUE if the current position is at the beginning of the list. | |
CubitBoolean | is_at_end () const |
Returns CUBIT_TRUE if the current position is at the end of the list. | |
void | reverse () |
Reverse the items in the list. | |
DLIList< X > & | operator= (const DLIList< X > &from) |
Create a copy of a list. | |
DLIList< X > & | operator= (const std::vector< X > &from) |
Create a DLIList from a std::vector. | |
DLIList< X > & | operator= (const DLIListIterator< X > &from_iterator) |
Create a copy of the list an iterator was obtained from. | |
DLIList< X > & | operator+= (const DLIList< X > &from) |
Append one list to another list. | |
DLIList< X > & | operator+= (const std::vector< X > &from) |
Append a std::vector to a DLIList. | |
DLIList< X > & | operator-= (const DLIList< X > &from) |
Subtract one list from another list. | |
int | operator== (const DLIList< X > &from) |
Compare two lists for equality. | |
int | operator!= (const DLIList< X > &from) |
Compare two lists for inequality. | |
const_reference | operator[] (int index) const |
Gets a reference to the element with the given index. | |
reference | operator[] (int index) |
reference | last_item (void) |
Gets a reference to the last element in the list. | |
const_reference | last_item (void) const |
void | merge_unique (const DLIList< X > &merge_list, bool merge_list_unique=false) |
Merges the contents of another list into this list. | |
template<typename Y > | |
void | casting_merge_unique (const DLIList< Y > &merge_list, bool merge_list_unique=false) |
Merges the contents of a list of a different type into this list. | |
void | intersect (const DLIList< X > &merge_list) |
Remove all elements that are not also in merge_list, preserving order. | |
void | intersect_unordered (const DLIList< X > &merge_list) |
Remove all elements that are not also in merge_list, not preserving order. | |
CubitBoolean | append_unique (const_reference new_item) |
Appends the new item to the list, but only if it isn't already in the list. | |
void | uniquify_unordered () |
Ensure each element of the list only appears once, not preserving order. | |
void | uniquify_unordered_checked () |
void | uniquify_ordered () |
Ensure each element of the list only appears once, preserving order. | |
X | remove () |
Removes the current item from the list. | |
bool | remove (const_reference val) |
Removes the next item with value val from the list. | |
void | remove_all_with_value (const_reference val) |
Remove all instances of a given value from the list. | |
CubitBoolean | omit (const_reference val) |
Removes all instances of a value from the list. | |
const_reference | get () const |
Returns a constant reference to the current item. | |
reference | get () |
X | next () const |
Returns the value at next position in the list. | |
X | next (int n) const |
Returns the value at n positions forward in list. | |
X | prev () const |
Returns the value at the previous position in list. | |
X | prev (int n) const |
Returns the value at n positions back in list. | |
reference | get_and_step () |
Returns a reference to the current item, then advances the current position by one. | |
reference | get_and_back () |
Returns a reference to the current item, then moves the current position back one. | |
reference | step_and_get () |
Advances the current position by one, then returns a reference to the current item. | |
CubitBoolean | move_to (const_reference item) |
Moves to the next instance of this value, wrapping if necessary. | |
CubitBoolean | is_in_list (const_reference item) const |
Return true if the item is in the list, false otherwise. | |
X | pop () |
Returns and removes last value in list. | |
X | push (X val) |
Puts a value on the end of the list. | |
void | insert (X val) |
Insert an item into the list, after current item. | |
void | insert_first (X val) |
Add a value at start of the list. | |
void | append (const_reference new_item) |
Place an item at the end of the list. | |
X | extract () |
Remove the current value and put last value in the list in its place. | |
X | change_to (X val) |
Change the value of the current item. | |
void | sort () |
Orders the list elements from lowest to highest. | |
void | sort (SortFunction f) |
Orders the list elements from lowest to highest, as defined by a function. | |
void | reserve (int min_size) |
Allocate enough space for at least min_size elements. | |
int | size () const |
Returns the number of items in the list. | |
bool | empty () const |
Returns if the list is empty or not. | |
int | get_index () |
Returns current index of the current position. | |
int | where_is_item (const_reference val) const |
Return the index of an item in list, or -1 if the item is not in the list. | |
int | memory_use () |
Returns the number of bytes allocated for this list's storage space. | |
void | copy_to (X *other_array) |
Copy this list's contents into an array. | |
void | copy_from (X *other_array, const int other_size) |
Copy items from an array into this list. | |
CubitBoolean | move_to_nearby (const X val) |
Moves to the nearest instance of val, searching both forward and backward. | |
int | distance_to_nearby (const X val) |
Returns the distance to the nearest element with a given value. | |
CubitBoolean | move_between (X val1, X val2) |
Set the current position to point at one of the two items, where the previous item is the other item. | |
const std::vector< X > & | as_vector () const |
Return a std::vector with the same contents as this list. | |
void | swap (std::vector< X > &other) |
Private Member Functions | |
void | lengthen_list (int by_how_much=DLI_COUNT_INCREMENT, double by_what_factor=DLI_COUNT_FACTOR) |
Private Attributes | |
int | index |
std::vector< X > | listArray |
Friends | |
class | DLIListIterator< X > |
Definition at line 78 of file DLIList.hpp.
typedef std::vector<X>::const_iterator DLIList< X >::const_iterator |
Definition at line 88 of file DLIList.hpp.
typedef std::vector<X>::const_pointer DLIList< X >::const_pointer |
Definition at line 86 of file DLIList.hpp.
typedef vector_const_reference_type<X>::type DLIList< X >::const_reference |
Definition at line 84 of file DLIList.hpp.
Definition at line 89 of file DLIList.hpp.
Definition at line 85 of file DLIList.hpp.
Definition at line 83 of file DLIList.hpp.
typedef int(* DLIList< X >::SortFunction)(X &a, X &b) |
A function which determines the relative order of objects.
The SortFunction should return a negative number if a should be before b, a positive number if b comes before a, and zero if they are equal, or relative order doesn't matter.
a | The first object in the comparison |
b | The second object in the comparison |
Definition at line 543 of file DLIList.hpp.
typedef std::vector<X>::value_type DLIList< X >::value_type |
Definition at line 91 of file DLIList.hpp.
Constructor: Create a list, allocating enough storage for size elements.
Although enough space is allocated for size elements, the list starts out empty (the size() function will return 0). If the requested memory size is 0, then storage is not allocated until the first element is added to the list. Additional storage space will be allocated if the list grows beyond its original size.
size | The amount of storage to pre-allocate for this list. |
Definition at line 1022 of file DLIList.hpp.
Copy constructor for std::vector.
from | The list to be copied. |
Definition at line 1039 of file DLIList.hpp.
Destructor: Free all resources used by this list.
The list and its storage space are freed. Note that if this is a list of pointers, this destructor will NOT delete the objects whose pointers are stored in the list.
Definition at line 1047 of file DLIList.hpp.
{ }
void DLIList< X >::append | ( | const_reference | new_item | ) | [inline] |
Place an item at the end of the list.
This is the most efficient way to insert an item to the list. The current position is unchanged.
val | The value to place at the end of the list. |
Definition at line 799 of file DLIList.hpp.
{ // see if the list must be lengthened if (listArray.capacity() == listArray.size()) lengthen_list(); listArray.push_back(new_item); }
CubitBoolean DLIList< X >::append_unique | ( | const_reference | new_item | ) | [inline] |
Appends the new item to the list, but only if it isn't already in the list.
In either case, the current position is not changed.
Definition at line 993 of file DLIList.hpp.
{ // Append new_item, if it isn't already there. if( where_is_item(new_item) < 0 ) { append (new_item); return CUBIT_TRUE; } return CUBIT_FALSE; }
Return a std::vector with the same contents as this list.
This function creates a std::vector from the DLIList and returns it.
Definition at line 1725 of file DLIList.hpp.
{ return listArray; }
Move the pointer to the previous element in the list.
If it reaches the beginning of the list, wrap around to the end.
Definition at line 737 of file DLIList.hpp.
Move the pointer n positions backward in the list.
The pointer will wrap around to the end of the list if the beginning is reached. If n is less than zero, move forward.
Definition at line 749 of file DLIList.hpp.
{ step(-n); }
return a begin iterator
Definition at line 1833 of file DLIList.hpp.
{ return this->listArray.begin(); }
return begin iterator
Definition at line 1839 of file DLIList.hpp.
{ return this->listArray.begin(); }
void DLIList< X >::casting_merge_unique | ( | const DLIList< Y > & | merge_list, |
bool | merge_list_unique = false |
||
) | [inline] |
Merges the contents of a list of a different type into this list.
This function is like merge_unique(), except that the type of object stored by merge_list is not the same as this list's type. The type of object stored in the other list must be able to be static_cast<> to this list's type.
merge_list | The list whose elements will be incorporated into this list. |
merge_list_unique | A flag indicating whether to skip a check for uniqueness between elements of merge_list. |
Definition at line 278 of file DLIList.hpp.
{ // Save the current index of the merge_list int old_size = size(); int i, j, check_index; X new_item; // The resulting list will be at least as large as the larger of the two lists. // Reserve space so we don't have to reallocate so often. Note that if // this list is already bigger than merge_list, the reserve won't // make the list shorter. assert((int)merge_list.size() >= 0); // Assume that the merge list size does not exceed the maximum value for a signed integer reserve(merge_list.size()); for ( i = 0; i < (int)merge_list.size(); i++) { // Get the item from the merge_list and insert it into "this" // list if it doesn't already exist there. new_item = static_cast<X>(merge_list[i]); check_index = merge_list_unique ? old_size : size(); // Append the new item and then remove it if necessary. append(new_item); for ( j = 0; j < check_index; j++ ) { if ( listArray[j] == new_item ) { listArray.resize(listArray.size()-1); break; } } } }
Change the value of the current item.
Because this function does not actually remove or insert an element, it is quite efficient. If the list is empty, the new value will not be inserted into the list.
Definition at line 925 of file DLIList.hpp.
Delete all elements in the list.
This function does not release memory already allocated for the list. This call is more efficient than creating a new list repeatedly within a loop.
Definition at line 785 of file DLIList.hpp.
Copy items from an array into this list.
Any prior contents of this list are removed. The list allocates additional storage if necessary to hold all of other_array's contents.
other_array | The array from which items will be copied. |
other_size | The number of items to be copied from other_array. |
Definition at line 1535 of file DLIList.hpp.
Copy this list's contents into an array.
It is assumed that other_array is big enough to hold all of this list's elements. No check is made to verify this.
other_array | The array into which this list's contents will be copied. |
Definition at line 1520 of file DLIList.hpp.
{ if(other_array == 0) throw std::invalid_argument("Array is NULL"); if (listArray.size() > 0) { const int itemCount = (int)listArray.size(); assert(itemCount >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer for (int i = 0; i < itemCount; i++) other_array[i] = listArray[i]; } }
int DLIList< X >::distance_to_nearby | ( | const X | val | ) | [inline] |
Returns the distance to the nearest element with a given value.
The returned value is always positive, regardless of whether the closest element is before or after the current position.
val | The value to search for. |
Definition at line 1609 of file DLIList.hpp.
Returns if the list is empty or not.
Definition at line 569 of file DLIList.hpp.
{ return listArray.empty(); }
Remove the current value and put last value in the list in its place.
If list order isn't important, this is much more efficient than remove().
Definition at line 1216 of file DLIList.hpp.
{ if ( listArray.empty() ) { throw std::out_of_range("Attempted link removal from empty DLIList\n"); /*PRINT_WARNING("Attempted link removal from empty DLIList\n");*/ } // save the current value X temp = listArray[index]; // assign last node to the current index listArray[index] = listArray[listArray.size() - 1]; // decrement listArray.resize(listArray.size() - 1); assert((int)listArray.size() >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer if ( index == (int)listArray.size() && index > 0) // The choices here are index at beginning or end. // End seems to work better when 'extract' is being used // with calls to 'move_to_item'. index--; return temp; }
Returns a constant reference to the current item.
Definition at line 819 of file DLIList.hpp.
Definition at line 808 of file DLIList.hpp.
Returns a reference to the current item, then moves the current position back one.
If the current position is at the beginning of the list, the function will wrap to the end of the list.
Definition at line 843 of file DLIList.hpp.
{ if ( listArray.empty() ) { throw std::out_of_range("Attempted get_and_back from empty DLIList\n"); /*PRINT_WARNING("Attempted get_and_back from empty DLIList\n");*/ } reference temp = listArray[index--]; assert((int)listArray.size() >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer if (index < 0) index = (int)listArray.size() - 1; return temp; }
Returns a reference to the current item, then advances the current position by one.
If the current position is at the end of the list, the function will wrap to the beginning of the list.
Definition at line 829 of file DLIList.hpp.
{ if ( listArray.empty() ) { throw std::out_of_range("Attempted get_and_step from empty DLIList\n"); /*PRINT_WARNING("Attempted get_and_step from empty DLIList\n");*/ } reference temp = listArray[index++]; assert((int)listArray.size() >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer if (index == (int)listArray.size()) index = 0; return temp; }
Returns current index of the current position.
Definition at line 574 of file DLIList.hpp.
{ return index; }
Insert an item into the list, after current item.
The newly inserted item becomes the current item. This function is inefficient due to bubbling.
val | The item to insert. |
Definition at line 1066 of file DLIList.hpp.
void DLIList< X >::insert_first | ( | X | val | ) | [inline] |
Add a value at start of the list.
The current position is set to the beginning of the list. Inefficient due to bubbling.
val | The value to place at the start of the list. |
Definition at line 906 of file DLIList.hpp.
Remove all elements that are not also in merge_list, preserving order.
This version is O(n^2). If the order of elements in the list does not matter, then consider using intersect_undordered(), which is O(n + sort_time).
merge_list | The list containing values to keep. |
Definition at line 1154 of file DLIList.hpp.
{ if ( &merge_list == this ) return; const int itemCount = (int)listArray.size(); assert(itemCount >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer std::vector<X> tmp; for ( int i=0; i<itemCount; i++ ) { if (merge_list.is_in_list(listArray[i])) { tmp.push_back(listArray[i]); } } this->listArray.swap(tmp); index = 0; }
void DLIList< X >::intersect_unordered | ( | const DLIList< X > & | merge_list | ) | [inline] |
Remove all elements that are not also in merge_list, not preserving order.
This version is O(n + sort_time). If the order of elements in the list is significant, then use intersect(), which is O(n^2) but preserves list order.
merge_list | The list containing values to keep. |
Definition at line 1096 of file DLIList.hpp.
{ if ( &merge_list == this ) return; intersect (merge_list); return; DLIList <X> intersect_list(merge_list); // copy input list so can sort sort(); intersect_list.sort(); typename std::vector<X>::iterator iter1 = listArray.begin(); // iterator for this array typename std::vector<X>::iterator end1 = listArray.end(); // end of this array typename std::vector<X>::iterator iter2 = intersect_list.listArray.begin(); // iterstor for other array typename std::vector<X>::iterator end2 = intersect_list.listArray.end();// end of other array typename std::vector<X>::iterator insertIt; // location of last insert bool first = true; for ( ; iter1 < end1; ++iter1 ) { while (iter2 < end2 && *iter2 < *iter1) ++iter2; if (iter2 == end2) break; // items are the same and ... if (*iter2 == *iter1) { // is the first item or ... if(first) { first = false; insertIt = listArray.begin(); *insertIt = *iter1; } // is not the same as the previous item else if(*iter1 != *insertIt) { *++insertIt = *iter1; } } } if(first) { // no intersections listArray.clear(); } else { listArray.resize(insertIt - listArray.begin() + 1); } reset(); }
CubitBoolean DLIList< X >::is_at_beginning | ( | ) | const [inline] |
Returns CUBIT_TRUE if the current position is at the beginning of the list.
Definition at line 767 of file DLIList.hpp.
{ if (!index) return CUBIT_TRUE; else return CUBIT_FALSE; }
CubitBoolean DLIList< X >::is_at_end | ( | ) | const [inline] |
Returns CUBIT_TRUE if the current position is at the end of the list.
Definition at line 775 of file DLIList.hpp.
{ const int itemCount = (int)listArray.size(); assert(itemCount >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer if (itemCount == 0 || index == itemCount - 1) return CUBIT_TRUE; else return CUBIT_FALSE; }
CubitBoolean DLIList< X >::is_in_list | ( | const_reference | item | ) | const [inline] |
Return true if the item is in the list, false otherwise.
Definition at line 791 of file DLIList.hpp.
{ return where_is_item(item) >= 0 ? CUBIT_TRUE : CUBIT_FALSE; }
Set the pointer to the end of the list.
Definition at line 759 of file DLIList.hpp.
Gets a reference to the last element in the list.
Definition at line 677 of file DLIList.hpp.
Definition at line 684 of file DLIList.hpp.
void DLIList< X >::lengthen_list | ( | int | by_how_much = DLI_COUNT_INCREMENT , |
double | by_what_factor = DLI_COUNT_FACTOR |
||
) | [inline, private] |
Definition at line 1056 of file DLIList.hpp.
int DLIList< X >::memory_use | ( | ) | [inline] |
Returns the number of bytes allocated for this list's storage space.
Definition at line 1506 of file DLIList.hpp.
void DLIList< X >::merge_unique | ( | const DLIList< X > & | merge_list, |
bool | merge_list_unique = false |
||
) | [inline] |
Merges the contents of another list into this list.
Each element in merge_list is added to this list, but only if it does not already appear in this list. The result is a list where no value appears twice.
This function runs faster if you know that no value is repeated in the merge_list. This is indicated with the merge_list_unique parameter. If merge_list_unique is true, then elements of will be checked against the original contents of this list, but not against the other elements of merge_list. If merge_list_unique is false, then each element will also be checked against the other elements of .
merge_list | The list whose elements will be incorporated into this list. |
merge_list_unique | A flag indicating whether to skip a check for uniqueness between elements of merge_list. |
Definition at line 1090 of file DLIList.hpp.
{ this->casting_merge_unique(merge_list, merge_list_unique); }
CubitBoolean DLIList< X >::move_between | ( | X | val1, |
X | val2 | ||
) | [inline] |
Set the current position to point at one of the two items, where the previous item is the other item.
This function looks for a place in the list where these two items are adjacent to each other, in either order. The current position is then set to the later of the two items. The function acts in a wrapped manner, such that the last item in the list is considered adjacent to the first item in the list.
val1 | One of the values to look for. |
val2 | The other value to look for. |
Definition at line 1625 of file DLIList.hpp.
{ { if ( listArray.empty() ) return CUBIT_FALSE; const int itemCount = (int)listArray.size(); assert(itemCount >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer for ( int i = 0; i < itemCount; i++ ) { if ( listArray[i] == item1 ) { // dance around looking for item2 if ( i+1 < itemCount ) { if ( listArray[i+1] == item2 ) { index = i+1; return CUBIT_TRUE; } } if ( i > 0 ) { if ( listArray[i-1] == item2 ) { index = i; return CUBIT_TRUE; } } if ( ( i+1 == itemCount && listArray[0] == item2 ) || ( i == 0 && listArray[itemCount-1] == item2 ) ) { index = 0; return CUBIT_TRUE; } } } return CUBIT_FALSE; } }
CubitBoolean DLIList< X >::move_to | ( | const_reference | item | ) | [inline] |
Moves to the next instance of this value, wrapping if necessary.
Definition at line 913 of file DLIList.hpp.
{ int item_index = where_is_item(item); CubitBoolean rv = CUBIT_FALSE; if (item_index >= 0) { index = item_index; rv = CUBIT_TRUE; } return rv; }
CubitBoolean DLIList< X >::move_to_nearby | ( | const X | val | ) | [inline] |
Moves to the nearest instance of val, searching both forward and backward.
Definition at line 1546 of file DLIList.hpp.
{ // if (nullItem && (X)nullItem == item) // return CUBIT_FALSE; // else if (listArray.empty()) return CUBIT_FALSE; else { const int itemCount = (int)listArray.size(); assert(itemCount >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer typename std::vector<X>::iterator ptr_up = listArray.begin() + index; if (*ptr_up == item) return CUBIT_TRUE; int i_up, i_down; i_up = i_down = index; typename std::vector<X>::iterator ptr_down = ptr_up; while (1) { // check forward in the list increment if ( ++i_up < itemCount ) ptr_up++; else { i_up = 0; ptr_up = listArray.begin(); } // check if ( *ptr_up == item ) { index = i_up; return CUBIT_TRUE; } if ( i_up == i_down ) { return CUBIT_FALSE; } // check backward in the list // increment if ( --i_down >= 0 ) ptr_down--; else { i_down = itemCount-1; ptr_down = listArray.begin()+ i_down; } // check if ( *ptr_down == item ) { index = i_down; return CUBIT_TRUE; } if ( i_up == i_down ) { return CUBIT_FALSE; } } } }
Returns the value at next position in the list.
The current position is not changed. If the current position is at the end of the list, the function wraps to the front of the list and returns the value of the first item.
Definition at line 857 of file DLIList.hpp.
{ if (listArray.empty()) { throw std::out_of_range("Attempted next of empty DLIList\n"); /*PRINT_WARNING("Attempted next of empty DLIList\n");*/ } else { assert((int)listArray.size() >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer if (index == (int)listArray.size() - 1) return listArray[0]; else return listArray[index + 1]; } }
Returns the value at n positions forward in list.
The current position is not changed. If n positions beyond the current position would move past the end of the list, the function wraps around to the start of the list.
n | The number of positions beyond the current position to return. |
Definition at line 873 of file DLIList.hpp.
{ if ( listArray.empty() ) { throw std::out_of_range("Attempted next of empty DLIList\n"); /*PRINT_WARNING("Attempted next of empty DLIList\n");*/ } else { // return the proper index // beware of negative n leading to negative new_index int new_index = index+n; assert((int)listArray.size() >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer while (new_index < 0) new_index += listArray.size(); if ((size_t)new_index >= listArray.size()) new_index %= listArray.size(); return listArray[new_index]; } }
CubitBoolean DLIList< X >::omit | ( | const_reference | val | ) | [inline] |
Removes all instances of a value from the list.
The current position of the list is not changed, unless the current item is removed from the list. If the current item is removed, then the current position is moved back one item, looping to the back of the list if necessary.
val | The value to remove from the list. |
Definition at line 1248 of file DLIList.hpp.
{ int scan_index; int squeeze_index = 0; CubitBoolean found = CUBIT_FALSE; const int itemCount = (int)listArray.size(); assert(itemCount >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer for(scan_index = 0; scan_index < itemCount; ++scan_index) { if(listArray[scan_index] == old_val) { found = CUBIT_TRUE; if(index == scan_index) index = squeeze_index - 1; } else { if(scan_index != squeeze_index) { listArray[squeeze_index] = listArray[scan_index]; if(index == scan_index) index = squeeze_index; } ++squeeze_index; } } if(found) { listArray.resize(squeeze_index); //+// If the first item was deleted and index pointed to it, make an //+// adjustment here. If itemCount is zero, don't assign -1 again. if(index < 0) index = listArray.empty() ? 0 : listArray.size()-1; } return found; }
Compare two lists for inequality.
Two lists are considered equal if they have the same contents. The elements do not need to be in the same order. If values are repeated, they do have to appear an equal number of times in each list.
from | The list to compare with this list. |
Definition at line 1356 of file DLIList.hpp.
{ return !( *this == from ); }
Append one list to another list.
This is the most efficient way to append two lists together.
from | The list to be appended to this list. |
Definition at line 1319 of file DLIList.hpp.
Append a std::vector to a DLIList.
This is the most efficient way to append two lists together.
from | The list to be appended to this list. |
Definition at line 1326 of file DLIList.hpp.
Subtract one list from another list.
Any element in which is also found in this list will be removed from this list. Element ordered is retained. The from list is not modified.
from | The list to be subtracted from this list. |
Definition at line 1333 of file DLIList.hpp.
{ // step through items in from list, removing them from this list. for (int i = from.listArray.size(); i--; ) { // quit early if this list is empty. if (listArray.empty()) break; remove_all_with_value(from.listArray[i]); } return *this; }
Create a DLIList from a std::vector.
This is the most efficient way to do this.
Definition at line 1311 of file DLIList.hpp.
DLIList< X > & DLIList< X >::operator= | ( | const DLIListIterator< X > & | from_iterator | ) | [inline] |
Create a copy of the list an iterator was obtained from.
If from_iterator is not associated with a list, then this list becomes empty.
from_iterator | An iterator to another list. |
Definition at line 649 of file DLIList.hpp.
{ if ( from_iter.dlIList ) *this = *(from_iter.dlIList); else clean_out(); return *this; }
Compare two lists for equality.
Two lists are considered equal if they have the same contents. The elements do not need to be in the same order. If values are repeated, they do have to appear an equal number of times in each list.
from | The list to compare with this list. |
Definition at line 1346 of file DLIList.hpp.
{ if(listArray.size() != from.listArray.size()) return CUBIT_FALSE; DLIList<X> temp_list = from; for( size_t i = 0; i < listArray.size(); i++) if(temp_list.move_to(listArray[i])) temp_list.remove(); return temp_list.listArray.size() == 0; }
DLIList< X >::const_reference DLIList< X >::operator[] | ( | int | index | ) | const [inline] |
Gets a reference to the element with the given index.
The index is zero-based.
index | The index to the desired element. |
Definition at line 659 of file DLIList.hpp.
Definition at line 668 of file DLIList.hpp.
Returns and removes last value in list.
Definition at line 1012 of file DLIList.hpp.
{ last(); return remove(); }
Returns the value at the previous position in list.
The current position is not changed. If the current position is at the beginning of the list, the function wraps to the end of the list and returns the value of the last item.
Definition at line 895 of file DLIList.hpp.
{ return this->next(-1); }
Returns the value at n positions back in list.
The current position is not changed. If n positions before the current position would move before the beginning of the list, the function wraps around to the end of the list.
n | The number of positions behind the current position to return. |
Definition at line 900 of file DLIList.hpp.
{ return this->next(-n); }
Puts a value on the end of the list.
The current position is then set to the end of the list.
val | The value to place at the end of the list. |
Definition at line 1004 of file DLIList.hpp.
Removes the current item from the list.
Remaining items with an index higher than the current item are moved up in the list. The current position is set to the next item in the list (i.e., the index does not change) unless the removed item was the last item in the list, in which case the current position is set to the beginning of the list.
Definition at line 1184 of file DLIList.hpp.
{ if ( listArray.empty() ) { throw std::out_of_range("Attempted link removal from empty DLIList\n"); /*PRINT_WARNING("Attempted link removal from empty DLIList\n");*/ } // save the current value X temp = listArray[index]; listArray.erase(listArray.begin() + index); assert((int)listArray.size() >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer if ( index == (int)listArray.size() ) { index = 0; } return temp; }
bool DLIList< X >::remove | ( | const_reference | val | ) | [inline] |
Removes the next item with value val from the list.
Only one element is removed from the list, even if the specified value occurs multiple times in the list. The list is searched from the current position to the end of the list, then from the beginning of the list to the current position. The current position continues to point at the same element, unless it is the element which was removed, in which case the behavior is identical to remove().
val | The value of the item to remove. |
Definition at line 956 of file DLIList.hpp.
{ if (move_to(item)) { remove(); return true; } return false; }
void DLIList< X >::remove_all_with_value | ( | const_reference | val | ) | [inline] |
Remove all instances of a given value from the list.
This function can be used to remove multiple items efficiently. First, change the value of any elements you want to remove to val. Next, call this function with that same value. This is more efficient than removing each element one at a time. After this function call, the current position is set to the start of the list.
Definition at line 940 of file DLIList.hpp.
Allocate enough space for at least min_size elements.
If there is already enough space allocated, the function does nothing; this function will never reduce the amount of memory allocated to the list.
min_size | The minimum number of elements to be prepared to store. |
Definition at line 1051 of file DLIList.hpp.
{ listArray.reserve(min_size); }
Set the pointer to the beginning of the list.
Definition at line 754 of file DLIList.hpp.
{ index = 0; }
Reverse the items in the list.
Definition at line 1489 of file DLIList.hpp.
{ int front = 0; assert((int)listArray.size() >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer int tail = (int)listArray.size() - 1; X temp; while (front < tail) { temp = listArray[front]; listArray[front] = listArray[tail]; listArray[tail] = temp; tail--; front++; } }
Reduces the size of the list by k.
No list storage is freed. Items in the array are not changed. If the current position is beyond the new end of the list, then the current position is moved to the new end of the list.
Definition at line 714 of file DLIList.hpp.
{ if (k > 0) { const int itemCount = (int)listArray.size(); assert(itemCount >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer if (itemCount > k) listArray.resize(itemCount - k); else listArray.clear(); const int itemNewCount = (int)listArray.size(); if (index >= itemNewCount) { if (itemNewCount > 0) index = itemNewCount - 1; else index = 0; } } }
Returns the number of items in the list.
Definition at line 564 of file DLIList.hpp.
{ return (int)listArray.size(); }
Orders the list elements from lowest to highest.
The sort order is determined by operator>= for the stored element type.
Use reverse after this call if you want to go the other direction.
Definition at line 1427 of file DLIList.hpp.
{ const int itemCount = (int)listArray.size(); assert(itemCount >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer // Only sort it if there is more than one // item in the list if (itemCount > 1) { //std::sort(listArray.begin(),listArray.end(),DLIListSorter<X>()); //return; int mid = (itemCount >> 1) + 1; int ir = itemCount; X temp_element; // You loop until ir is 1 (ir = iterations remaining) while(CUBIT_TRUE) { if (mid > 1) { mid--; temp_element = listArray[mid - 1]; } else { ir--; temp_element = listArray[ir]; listArray[ir] = listArray[0]; if (ir == 1) { listArray[0] = temp_element; return; } } int i = mid; int j = mid + mid; while (j <= ir) { if (j < ir) { if (listArray[j] >= listArray[j - 1]) j++; } if (listArray[j - 1] >= temp_element) { listArray[i - 1] = listArray[j - 1]; i = j; j += j; } else { j = ir + 1; } } listArray[i - 1] = temp_element; } } }
void DLIList< X >::sort | ( | SortFunction | f | ) |
Orders the list elements from lowest to highest, as defined by a function.
The sort order is determined by the passed in SortFunction.
Use reverse after this call if you want to go the other direction.
f | The function which determines the sort order. |
Move the pointer to the next element in the list.
If pointer reaches the end of the list, wrap around to the beginning
Definition at line 690 of file DLIList.hpp.
Move the pointer n positions forward in the list.
The pointer will wrap around to the beginning of the list if the end is reached. If n is less than zero, move backward.
n | The number of positions to move forward or backward. |
Definition at line 699 of file DLIList.hpp.
Advances the current position by one, then returns a reference to the current item.
If the current position is at the end of the list, the function will wrap to the beginning of the list.
Definition at line 1286 of file DLIList.hpp.
{ if ( listArray.empty() ) { throw std::out_of_range("Attempted step_and_get from empty DLIList\n"); /*PRINT_WARNING("Attempted step_and_get from empty DLIList\n");*/ } assert((int)listArray.size() >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer if (++index == (int)listArray.size()) index = 0; return listArray[index]; }
Definition at line 1856 of file DLIList.hpp.
{ this->listArray.swap(other); }
void DLIList< X >::uniquify_ordered | ( | ) | [inline] |
Ensure each element of the list only appears once, preserving order.
The order of elements is preserved, but at a speed cost compared to uniquify_unordered(). The current position is set to 0.
Definition at line 1702 of file DLIList.hpp.
{ std::set<X> encountered; typename std::vector<X>::iterator read_iter, write_iter, end_iter = listArray.end(); // To avoid copying the array onto itself in the case // where the list contains no duplicates, loop twice. // Find first duplicate entry. for ( read_iter = listArray.begin(); read_iter != end_iter; ++read_iter ) if ( ! encountered.insert(*read_iter).second ) break; // Now compact array, removing duplicates. If there // are no duplicates, this loop will not run (read_iter == end_iter). for ( write_iter = read_iter; read_iter != end_iter; ++read_iter ) if ( encountered.insert(*read_iter).second ) *(write_iter++) = *read_iter; listArray.resize(write_iter - listArray.begin()); index = 0; }
void DLIList< X >::uniquify_unordered | ( | ) | [inline] |
Ensure each element of the list only appears once, not preserving order.
The list is first sorted for speed, so the order of elements may change. The current position is set to 0.
Definition at line 1665 of file DLIList.hpp.
void DLIList< X >::uniquify_unordered_checked | ( | ) | [inline] |
int DLIList< X >::where_is_item | ( | const_reference | val | ) | const [inline] |
Return the index of an item in list, or -1 if the item is not in the list.
The location of the first instance of val is returned as a zero-based index from the start of the list. The list is searched starting from the current position, wrapping to the front of the list if necessary.
val | The value to search for. |
Definition at line 966 of file DLIList.hpp.
{ if (listArray.empty()) return -1; const int itemCount = (int)listArray.size(); assert(itemCount >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer // loop through list searching for item ... // if found return index // Search from current index to end of array int i; for (i=index; i < itemCount; i++) if (listArray[i] == item) return i; // Now search from beginning of array to index... for (i = 0; i < index && i < itemCount; i++) if (listArray[i] == item) return i; // item is not in array, return -1 return -1; }
friend class DLIListIterator< X > [friend] |
Definition at line 81 of file DLIList.hpp.
Definition at line 643 of file DLIList.hpp.
Definition at line 644 of file DLIList.hpp.