cgma
DLIList< X > Class Template Reference

#include <DLIList.hpp>

List of all members.

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< XlistArray

Friends

class DLIListIterator< X >

Detailed Description

template<class X>
class DLIList< X >

Definition at line 78 of file DLIList.hpp.


Member Typedef Documentation

template<class X>
typedef std::vector<X>::const_iterator DLIList< X >::const_iterator

Definition at line 88 of file DLIList.hpp.

template<class X>
typedef std::vector<X>::const_pointer DLIList< X >::const_pointer

Definition at line 86 of file DLIList.hpp.

template<class X>
typedef vector_const_reference_type<X>::type DLIList< X >::const_reference

Definition at line 84 of file DLIList.hpp.

template<class X>
typedef std::vector<X>::iterator DLIList< X >::iterator

Definition at line 89 of file DLIList.hpp.

template<class X>
typedef std::vector<X>::pointer DLIList< X >::pointer

Definition at line 85 of file DLIList.hpp.

template<class X>
typedef std::vector<X>::reference DLIList< X >::reference

Definition at line 83 of file DLIList.hpp.

template<class X>
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.

Parameters:
aThe first object in the comparison
bThe second object in the comparison
See also:
sort(SortFunction f)

Definition at line 543 of file DLIList.hpp.

template<class X>
typedef std::vector<X>::value_type DLIList< X >::value_type

Definition at line 91 of file DLIList.hpp.


Constructor & Destructor Documentation

template<class X >
DLIList< X >::DLIList ( int  size = 0) [inline, explicit]

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.

Parameters:
sizeThe amount of storage to pre-allocate for this list.

Definition at line 1022 of file DLIList.hpp.

{
   index      = 0;
   listArray.reserve(sizeIn);
}
template<class X>
DLIList< X >::DLIList ( const DLIList< X > &  from) [inline]

Copy constructor.

Parameters:
fromThe list to be copied.

Definition at line 1029 of file DLIList.hpp.

{
   if (&from != this)
   {
     index = from.index;
     listArray = from.listArray;
   }
}
template<class X>
DLIList< X >::DLIList ( const std::vector< X > &  from) [inline, explicit]

Copy constructor for std::vector.

Parameters:
fromThe list to be copied.

Definition at line 1039 of file DLIList.hpp.

{
    // Setup the variables
    index = 0;
    listArray = from;
}
template<class X >
DLIList< X >::~DLIList ( ) [inline]

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.

{
}

Member Function Documentation

template<class X >
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.

Parameters:
valThe 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);
}
template<class X >
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.

Returns:
CUBIT_TRUE if the item was added, otherwise CUBIT_FALSE.

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;
}
template<class X >
const std::vector< X > & DLIList< X >::as_vector ( ) const [inline]

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;
}
template<class X >
void DLIList< X >::back ( ) [inline]

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.

{
  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--;
    if (index < 0)
      index = itemCount - 1;
  }
}
template<class X >
void DLIList< X >::back ( int  n) [inline]

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);
}
template<class X >
DLIList< X >::iterator DLIList< X >::begin ( ) [inline]

return a begin iterator

Definition at line 1833 of file DLIList.hpp.

{
  return this->listArray.begin();
}
template<class X >
DLIList< X >::const_iterator DLIList< X >::begin ( ) const [inline]

return begin iterator

Definition at line 1839 of file DLIList.hpp.

{
  return this->listArray.begin();
}
template<class X>
template<typename Y >
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.

Parameters:
merge_listThe list whose elements will be incorporated into this list.
merge_list_uniqueA flag indicating whether to skip a check for uniqueness between elements of merge_list.
See also:
merge_unique()

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;
          }
        }
      }
    }
template<class X>
X DLIList< X >::change_to ( X  val) [inline]

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.

Returns:
The former value of the current item, or X(0) if the list was empty.

Definition at line 925 of file DLIList.hpp.

{
  if ( listArray.empty() )
  {
    throw std::out_of_range("DLIList: Attempted update of empty list\n");
    //PRINT_WARNING("DLIList: Attempted update of empty list\n");
  }

  X temp = listArray[index];
  listArray[index] = new_value;
  return temp;
}
template<class X >
void DLIList< X >::clean_out ( ) [inline]

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.

{
  listArray.clear();
  index = 0;
}
template<class X>
void DLIList< X >::copy_from ( X other_array,
const int  other_size 
) [inline]

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.

Parameters:
other_arrayThe array from which items will be copied.
other_sizeThe number of items to be copied from other_array.

Definition at line 1535 of file DLIList.hpp.

{
  if(other_array == 0)
    throw std::invalid_argument("Array is NULL");

  listArray.clear();
  listArray.insert(listArray.end(), other_array, other_array+other_size);
  index = 0;
}
template<class X>
void DLIList< X >::copy_to ( X other_array) [inline]

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.

Parameters:
other_arrayThe 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];
  }
}
template<class X>
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.

Parameters:
valThe value to search for.
Returns:
The distance to the closest element with value val.

Definition at line 1609 of file DLIList.hpp.

{
//  if (nullItem && (X)nullItem == body)
//     return CUBIT_FALSE;
//  else
  {
    int old_index = index;
    move_to_nearby( body );
    int distance = abs(index - old_index);
    if (distance > listArray.size() / 2)
       distance = listArray.size() - distance;
    index = old_index;
    return distance;
  }
}
template<class X>
bool DLIList< X >::empty ( ) const [inline]

Returns if the list is empty or not.

Returns:
true or false

Definition at line 569 of file DLIList.hpp.

  { return listArray.empty(); }
template<class X >
DLIList< X >::iterator DLIList< X >::end ( ) [inline]

return end iterator

Definition at line 1845 of file DLIList.hpp.

{
  return this->listArray.end();
}
template<class X >
DLIList< X >::const_iterator DLIList< X >::end ( ) const [inline]

return end iterator

Definition at line 1851 of file DLIList.hpp.

{
  return this->listArray.end();
}
template<class X >
X DLIList< X >::extract ( ) [inline]

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().

Returns:
The value removed from the list, or X(0) if the list was empty.

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;
}
template<class X >
DLIList< X >::const_reference DLIList< X >::get ( ) const [inline]

Returns a constant reference to the current item.

Returns:
A constant reference to the current item. If the list is empty, an exception is thrown.

Definition at line 819 of file DLIList.hpp.

{
  if ( listArray.empty() )
  {
    throw std::out_of_range("Attempted get of empty DLIList\n");
    /*PRINT_WARNING("Attempted get of empty DLIList\n");*/
  }
  return listArray[index];
}
template<class X >
DLIList< X >::reference DLIList< X >::get ( ) [inline]

Definition at line 808 of file DLIList.hpp.

{
  if ( listArray.empty() )
  {
    throw std::out_of_range("Attempted get of empty DLIList\n");
    /*PRINT_WARNING("Attempted get of empty DLIList\n");*/
  }

  return listArray[index];
}
template<class X >
DLIList< X >::reference DLIList< X >::get_and_back ( ) [inline]

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.

Returns:
A reference to the item at the current position, before stepping back. If the list is empty, an exception is thrown.

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;
}
template<class X >
DLIList< X >::reference DLIList< X >::get_and_step ( ) [inline]

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.

Returns:
A reference to the item at the current position, before stepping.

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;
}
template<class X>
int DLIList< X >::get_index ( ) [inline]

Returns current index of the current position.

Returns:
the current position

Definition at line 574 of file DLIList.hpp.

     { return index; }
template<class X>
void DLIList< X >::insert ( X  val) [inline]

Insert an item into the list, after current item.

The newly inserted item becomes the current item. This function is inefficient due to bubbling.

Parameters:
valThe item to insert.

Definition at line 1066 of file DLIList.hpp.

{
     // see if the list must be lengthened
   if ( listArray.size() == listArray.capacity())
   {
      lengthen_list();
   }

     // set new index
   if ( !listArray.empty() )
   {
      index++;
   }
   else
   {
      index = 0;
   }

   listArray.insert(listArray.begin()+index, new_item);
}
template<class X>
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.

Parameters:
valThe value to place at the start of the list.

Definition at line 906 of file DLIList.hpp.

{
  // set index to -1 ... index will be set to 0 in insert
  index = -1;
  insert(new_item);
}
template<class X>
void DLIList< X >::intersect ( const DLIList< X > &  merge_list) [inline]

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).

Parameters:
merge_listThe list containing values to keep.
See also:
intersect_unordered(const DLIList<X>& merge_list)

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;
}
template<class X>
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.

Parameters:
merge_listThe list containing values to keep.
See also:
intersect(const DLIList<X>& merge_list)

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();
}
template<class X >
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;
}
template<class X >
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;
}
template<class X >
CubitBoolean DLIList< X >::is_in_list ( const_reference  item) const [inline]

Return true if the item is in the list, false otherwise.

Returns:
Returns true if the item was found in the list, otherwise returns false.

Definition at line 791 of file DLIList.hpp.

{
  return where_is_item(item) >= 0 ? CUBIT_TRUE : CUBIT_FALSE;
}
template<class X >
void DLIList< X >::last ( ) [inline]

Set the pointer to the end of the list.

Definition at line 759 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;
}
template<class X >
DLIList< X >::reference DLIList< X >::last_item ( void  ) [inline]

Gets a reference to the last element in the list.

Definition at line 677 of file DLIList.hpp.

{
    assert( listArray.size() > 0 );
    return listArray[listArray.size()-1];
}
template<class X >
DLIList< X >::const_reference DLIList< X >::last_item ( void  ) const [inline]

Definition at line 684 of file DLIList.hpp.

{
    assert( listArray.size() > 0 );
    return listArray[listArray.size()-1];
}
template<class X >
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.

{
    // Make a new array
  int new_size = (int) ((double)listArray.capacity() * by_what_factor) + by_how_much;
  assert(new_size > 0);
  reserve(new_size);
}
template<class X >
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.

{
   // report amount of memory allocated

   int sizeIn = listArray.capacity() * sizeof(X);

//   if (verbose_boolean)
//   {
//      PRINT_INFO("      DLIList: %d bytes\n",sizeIn);
//   }

   return sizeIn;
}
template<class X>
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 .

Parameters:
merge_listThe list whose elements will be incorporated into this list.
merge_list_uniqueA 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);
}
template<class X>
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.

Parameters:
val1One of the values to look for.
val2The other value to look for.
Returns:
true if the two items are found adjacent to each other, false otherwise.

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;
  }
}
template<class X >
CubitBoolean DLIList< X >::move_to ( const_reference  item) [inline]

Moves to the next instance of this value, wrapping if necessary.

Returns:
Returns true if the item was found in the list, otherwise returns false.

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;
}
template<class X>
CubitBoolean DLIList< X >::move_to_nearby ( const X  val) [inline]

Moves to the nearest instance of val, searching both forward and backward.

Returns:
True if an item with the specified value was found, false otherwise.

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;
      }

    }
  }
}
template<class X >
X DLIList< X >::next ( ) const [inline]

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.

Returns:
The value of the next item. If the list is empty, an exception is thrown.

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];
  }
}
template<class X >
X DLIList< X >::next ( int  n) const [inline]

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.

Parameters:
nThe number of positions beyond the current position to return.
Returns:
The value of the item n positions beyond the current position. If the list is empty, an exception is thrown.

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];
  }
}
template<class X >
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.

Parameters:
valThe value to remove from the list.
Returns:
CUBIT_TRUE if at least one instance the item was removed, CUBIT_FALSE if not.
See also:
remove()
remove(X val)
remove_all_with_value(X val)

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;
}
template<class X>
int DLIList< X >::operator!= ( const DLIList< X > &  from) [inline]

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.

Parameters:
fromThe list to compare with this list.
Returns:
False if the lists are equal, true otherwise.

Definition at line 1356 of file DLIList.hpp.

{
  return !( *this == from );
}
template<class X>
DLIList< X > & DLIList< X >::operator+= ( const DLIList< X > &  from) [inline]

Append one list to another list.

This is the most efficient way to append two lists together.

Parameters:
fromThe list to be appended to this list.
Returns:
A reference to this list.

Definition at line 1319 of file DLIList.hpp.

{
   listArray.insert(listArray.end(), from.listArray.begin(), from.listArray.end());
   return *this;
}
template<class X>
DLIList< X > & DLIList< X >::operator+= ( const std::vector< X > &  from) [inline]

Append a std::vector to a DLIList.

This is the most efficient way to append two lists together.

Parameters:
fromThe list to be appended to this list.
Returns:
A reference to this list.

Definition at line 1326 of file DLIList.hpp.

{
  listArray.insert(listArray.end(), from.begin(), from.end());
  return *this;
}
template<class X>
DLIList< X > & DLIList< X >::operator-= ( const DLIList< X > &  from) [inline]

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.

Parameters:
fromThe list to be subtracted from this list.
Returns:
A reference to 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;
}
template<class X>
DLIList< X > & DLIList< X >::operator= ( const DLIList< X > &  from) [inline]

Create a copy of a list.

This is the most efficient way to do this.

Returns:
A reference to this list.

Definition at line 1300 of file DLIList.hpp.

{
   if (this != &from)
   {
      index = from.index;
      listArray = from.listArray;
   }
   return *this;
}
template<class X>
DLIList< X > & DLIList< X >::operator= ( const std::vector< X > &  from) [inline]

Create a DLIList from a std::vector.

This is the most efficient way to do this.

Returns:
A reference to this list.

Definition at line 1311 of file DLIList.hpp.

{
  index = 0;
  listArray = from;
  return *this;
}
template<class X>
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.

Parameters:
from_iteratorAn iterator to another list.
Returns:
A reference to this list.

Definition at line 649 of file DLIList.hpp.

{ 
  if ( from_iter.dlIList ) 
    *this = *(from_iter.dlIList); 
  else
    clean_out();
  return *this; 
}
template<class X>
int DLIList< X >::operator== ( const DLIList< X > &  from) [inline]

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.

Parameters:
fromThe list to compare with this list.
Returns:
True if the lists are equal, false otherwise.

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;
}
template<class X >
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.

Parameters:
indexThe index to the desired element.
Returns:
A reference to the indicated element.

Definition at line 659 of file DLIList.hpp.

{
  assert((int)listArray.size() >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer
  if(indexIn < 0 || (size_t)indexIn >= listArray.size())
    throw std::out_of_range("Index out of Bounds\n");
  return listArray[indexIn];
}
template<class X >
DLIList< X >::reference DLIList< X >::operator[] ( int  index) [inline]

Definition at line 668 of file DLIList.hpp.

{
  assert((int)listArray.size() >= 0); // Assume that the listArray size does not exceed the maximum value for a signed integer
  if(indexIn < 0 || (size_t)indexIn >= listArray.size())
    throw std::out_of_range("Index out of Bounds\n");
  return listArray[indexIn];
}
template<class X >
X DLIList< X >::pop ( ) [inline]

Returns and removes last value in list.

Returns:
Returns the last value in the list. If the list is empty, returns X(0).

Definition at line 1012 of file DLIList.hpp.

{
  last();
  return remove();
}
template<class X >
X DLIList< X >::prev ( ) const [inline]

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.

Returns:
The value of the previous item. If the list is empty, an exception is thrown.

Definition at line 895 of file DLIList.hpp.

{
  return this->next(-1);
}
template<class X >
X DLIList< X >::prev ( int  n) const [inline]

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.

Parameters:
nThe number of positions behind the current position to return.
Returns:
The value of the item n positions before the current position. If the list is empty, an exception is thrown.

Definition at line 900 of file DLIList.hpp.

{
  return this->next(-n);
}
template<class X>
X DLIList< X >::push ( X  val) [inline]

Puts a value on the end of the list.

The current position is then set to the end of the list.

Parameters:
valThe value to place at the end of the list.
Returns:
The value placed on the end of the list.
See also:
push_back(X val)

Definition at line 1004 of file DLIList.hpp.

{
  //- swapped last and append; current position is set new end
   append(value);
   last();
   return value;
}
template<class X >
X DLIList< X >::remove ( ) [inline]

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.

Returns:
The removed item.
See also:
remove(X val)
remove_all_with_value(X val)
omit(X val)

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;
}
template<class X >
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().

Parameters:
valThe value of the item to remove.
Returns:
Whether the item was found and removed.
See also:
remove()
remove_all_with_value(X val)
omit(X val)

Definition at line 956 of file DLIList.hpp.

{
  if (move_to(item))
  {
    remove();
    return true;
  }
  return false;
}
template<class X >
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.

See also:
remove()
remove(X val)
omit(X val)

Definition at line 940 of file DLIList.hpp.

{
  size_t j = 0;
  size_t i = 0;
  const size_t itemCount = listArray.size();

  for ( ; i < itemCount; i++)
    if (listArray[i] != val && j++ != i)
      listArray[j-1] = listArray[i];

  listArray.resize(j);
  index = 0;
}
template<class X >
void DLIList< X >::reserve ( int  min_size) [inline]

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.

Parameters:
min_sizeThe minimum number of elements to be prepared to store.

Definition at line 1051 of file DLIList.hpp.

{
  listArray.reserve(min_size);
}
template<class X >
void DLIList< X >::reset ( ) [inline]

Set the pointer to the beginning of the list.

Definition at line 754 of file DLIList.hpp.

{
  index = 0;
}
template<class X >
void DLIList< X >::reverse ( ) [inline]

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++;
  }
}
template<class X >
void DLIList< X >::shrink ( int  k) [inline]

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;
    }
  }
}
template<class X>
int DLIList< X >::size ( ) const [inline]

Returns the number of items in the list.

Returns:
The number of items current in the list.

Definition at line 564 of file DLIList.hpp.

    { return (int)listArray.size(); }
template<class X >
void DLIList< X >::sort ( ) [inline]

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;
    }
  }

}
template<class X>
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.

Parameters:
fThe function which determines the sort order.
See also:
SortFunction
template<class X >
void DLIList< X >::step ( ) [inline]

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.

{
  if (!listArray.empty())
    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;
}
template<class X >
void DLIList< X >::step ( int  n) [inline]

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.

Parameters:
nThe number of positions to move forward or backward.

Definition at line 699 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 += n;
    if (index < 0)
      index = itemCount - (-index) % itemCount;
    if (index >= itemCount)
      index %= itemCount;
  }
}
template<class X >
DLIList< X >::reference DLIList< X >::step_and_get ( ) [inline]

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.

Returns:
A reference to the item at the current position, after stepping.

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];
}
template<class X>
void DLIList< X >::swap ( std::vector< X > &  other) [inline]

Definition at line 1856 of file DLIList.hpp.

{
  this->listArray.swap(other);
}
template<class X >
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.

See also:
uniquify_unordered()

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;
}
template<class X >
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.

See also:
uniquify_ordered()

Definition at line 1665 of file DLIList.hpp.

{
  const size_t itemCount = listArray.size();
  if ( itemCount < 2 )
    return;

  sort();

  listArray.erase(std::unique(listArray.begin(), listArray.end()), listArray.end());

  index = 0;
}
template<class X >
void DLIList< X >::uniquify_unordered_checked ( ) [inline]

Definition at line 1679 of file DLIList.hpp.

{
  const size_t itemCount = listArray.size();
  if ( itemCount < 2 )
    return;

  sort();

  size_t j = 1;
  size_t i = 0;

  while (j < itemCount)
  {
    if (listArray[i] != listArray[j])
      listArray[++i] = listArray[j++];
    else
      j++;
  }

  listArray.resize(i + 1);
  index = 0;
}
template<class X >
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.

Parameters:
valThe value to search for.
Returns:
The index of the first instance of val, or -1 if the value is not found.

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;
}

Friends And Related Function Documentation

template<class X>
friend class DLIListIterator< X > [friend]

Definition at line 81 of file DLIList.hpp.


Member Data Documentation

template<class X>
int DLIList< X >::index [private]

Definition at line 643 of file DLIList.hpp.

template<class X>
std::vector<X> DLIList< X >::listArray [private]

Definition at line 644 of file DLIList.hpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines