Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::HTList Class Reference

Single linked list of nodes. More...

#include <htlist.H>

Inheritance diagram for Aleph::HTList:
[legend]
Collaboration diagram for Aleph::HTList:
[legend]

Classes

class  Iterator
 

Public Member Functions

 HTList () noexcept
 
void reset () noexcept
 
constexpr bool is_empty () const noexcept
 
bool is_unitarian () const noexcept
 Return true if the list contains exactly just one.
 
bool is_unitarian_or_empty () const noexcept
 Return true if list contains one element or is empty.
 
Slinknc * get_head () const noexcept
 
Slinknc * get_tail () const noexcept
 
Slinknc * get_first () const noexcept
 
Slinknc * get_first_ne () const noexcept
 Return the first item of the list; the list must not be empty.
 
Slinknc * get_last () const noexcept
 Return the last item of the list (nullptr if the list is empty)
 
HTList & swap (HTList &l) noexcept
 
void insert (Slinknc *link) noexcept
 
void append (Slinknc *link) noexcept
 
void append (HTList &l) noexcept
 
void put (Slinknc *link) noexcept
 
void concat (HTList &l) noexcept
 Concat to 'this' all 'l' list; 'l' becomes empty.
 
void concat_list (HTList &l) noexcept
 See concat(HTList & l).
 
void insert (HTList &l) noexcept
 Insert starting in link (contained in 'this' list) the.
 
void insert (Slinknc *link, HTList &list) noexcept
 Insert a list into this after one of its items.
 
Slinknc * remove_head_ne () noexcept
 It deletes head element (first one). Return deleted.
 
Slinknc * remove_head ()
 Remove the header item from the list.
 
Slinknc * remove_first_ne () noexcept
 Remove the header item from the list.
 
Slinknc * remove_first ()
 
bool remove (Slinknc *link)
 
void push (Slinknc *link) noexcept
 
Slinknc * pop ()
 Remove the first item of this.
 
Slinknc * top () const
 
size_t split_list (HTList &l, HTList &r) noexcept
 It divides 'this' into two equal lists without modifying.
 
size_t split_list_ne (HTList &l, HTList &r) noexcept
 
size_t split (HTList &l, HTList &r) noexcept
 See split_list(HTList & l, HTList & r).
 
size_t reverse () noexcept
 It inverts all list elements. It returns list size.
 
size_t reverse_list () noexcept
 See reverse().
 
void cut (Slinknc *link, HTList &list) noexcept
 It cuts 'this' over 'link' element and it puts all.
 
void cut_list (Slinknc *link, HTList &list) noexcept
 See cut(Slinknc * link, HTList & list).
 
void remove_all_and_delete () noexcept
 
size_t size () const noexcept
 Count the number of elements of the list.
 
void rotate_left (size_t n)
 Rotate to left the list n positions.
 

Private Attributes

Slinknc * head
 
Slinknc * tail
 

Detailed Description

Single linked list of nodes.

HTList models a list of nodes of type Slinknc. A Slinknc object is a link that could be contained inside any data structure. The possibility for belonging to a HTList is defined for the owner of one o more objects of typeSlinknc`.

A HTlist object maintains two references. The first one is called head" and corresponds to the first node. The second one is called <tt>tail</tt> and corresponds to last node. Take in account that this class does not manage memory neither access to the data that could be stored in the nodes. Slinknc y Snodenc. However, since this class is inherited by other more sophisticated classes, we will use the term "item" instead of node for referring an element of this list of nodes.

See also
Slinknc Snodenc DynList
Author
Alejandro Mujica
Leandro Rabindranath León

Definition at line 419 of file htlist.H.

Constructor & Destructor Documentation

◆ HTList()

Aleph::HTList::HTList ( )
inlinenoexcept

Definition at line 425 of file htlist.H.

Member Function Documentation

◆ append() [1/2]

void Aleph::HTList::append ( HTList &  l)
inlinenoexcept
Parameters
[in]lList that will be inserted through list end

Definition at line 537 of file htlist.H.

References head, is_empty(), l, NEXT, swap(), and tail.

◆ append() [2/2]

void Aleph::HTList::append ( Slinknc *  link)
inlinenoexcept

◆ concat()

void Aleph::HTList::concat ( HTList &  l)
inlinenoexcept

Concat to 'this' all 'l' list; 'l' becomes empty.

Definition at line 560 of file htlist.H.

References append(), and l.

◆ concat_list()

void Aleph::HTList::concat_list ( HTList &  l)
inlinenoexcept

See concat(HTList & l).

Definition at line 566 of file htlist.H.

References append(), and l.

Referenced by Aleph::quicksort().

◆ cut()

void Aleph::HTList::cut ( Slinknc *  link,
HTList &  list 
)
inlinenoexcept

It cuts 'this' over 'link' element and it puts all.

list

 \brief  It makes reference to is_empty(). <br>

Referenced by cut_list().

Parameters
[in]linkElement where 'list' will be cut.
[in]listList that will be cut in link

Definition at line 849 of file htlist.H.

References NEXT, and tail.

Referenced by Aleph::DynList< T >::cut(), cut_list(), main(), Aleph::DynList< T >::split_list_ne(), and TEST_F().

◆ cut_list()

void Aleph::HTList::cut_list ( Slinknc *  link,
HTList &  list 
)
inlinenoexcept

See cut(Slinknc * link, HTList & list).

Definition at line 861 of file htlist.H.

References cut().

◆ get_first()

◆ get_first_ne()

Slinknc * Aleph::HTList::get_first_ne ( ) const
inlinenoexcept

Return the first item of the list; the list must not be empty.

Definition at line 469 of file htlist.H.

References head.

◆ get_head()

Slinknc * Aleph::HTList::get_head ( ) const
inlinenoexcept

Definition at line 453 of file htlist.H.

References head.

Referenced by get_first(), and TEST().

◆ get_last()

Slinknc * Aleph::HTList::get_last ( ) const
inlinenoexcept

Return the last item of the list (nullptr if the list is empty)

Definition at line 475 of file htlist.H.

References get_tail().

Referenced by Aleph::DynList< T >::empty(), Aleph::DynList< T >::get_last_ne(), Aleph::DynList< T >::get_last_ne(), Aleph::insert_sorted(), TEST(), TEST(), TEST(), and TEST().

◆ get_tail()

Slinknc * Aleph::HTList::get_tail ( ) const
inlinenoexcept

Definition at line 458 of file htlist.H.

References tail.

Referenced by get_last(), and TEST().

◆ insert() [1/3]

void Aleph::HTList::insert ( HTList &  l)
inlinenoexcept

Insert starting in link (contained in 'this' list) the.

 Insert list `l` starting from `this`. After insertion, `l` becomes empty.
Parameters
[in,out]lList that will be inserted starting from this. After the call, l is empty.

Definition at line 580 of file htlist.H.

References Aleph::DynList< T >::append(), l, and swap().

◆ insert() [2/3]

void Aleph::HTList::insert ( Slinknc *  link)
inlinenoexcept
Parameters
[in]linkNew element that will be inserted

Definition at line 499 of file htlist.H.

References head, NEXT, and tail.

Referenced by Aleph::DynList< T >::__insert(), Aleph::DynList< T >::insert(), Aleph::insert_sorted(), main(), push(), reverse(), TEST(), and TEST().

◆ insert() [3/3]

void Aleph::HTList::insert ( Slinknc *  link,
HTList &  list 
)
inlinenoexcept

Insert a list into this after one of its items.

insert(link, list) assumes that link points to a item of this and inserts in constant time list just after the item pointed by link. The order of list is not altered. but list becomes empty after insertion.

Suppose the following situation

this-->t1-->t2-->t3-->t4-->t5-->t6-->t7-->t8
                ^

| link

l-->l1-->l2-->l3-->l4

Then insert(link, list) produces:

this-->t1-->t2-->t3-->t4-->l1-->l2-->l3-->l4-->t5-->t6-->t7-->t8

l becomes empty

Parameters
[in]linkto the item after one wants to insert list
[in]listto be inserted after item pointed by link

Definition at line 613 of file htlist.H.

References NEXT, and tail.

◆ is_empty()

constexpr bool Aleph::HTList::is_empty ( ) const
inlineconstexprnoexcept

Definition at line 434 of file htlist.H.

References head.

Referenced by Aleph::Dlink::Dlink(), append(), Aleph::DynList< T >::empty(), Aleph::DynListQueue< T >::empty(), Aleph::Gen_Polynomial< Coefficient >::factorize(), Aleph::Find_Eulerian_Path< GT, SN, SA >::find_node_sequence(), Aleph::ShortestPathInPolygon::find_sleeve(), Aleph::k_shortest_paths_detail::generate_general_deviation_candidates(), Aleph::DynList< T >::get_first(), Aleph::DynList< T >::get_first(), Aleph::DynList< T >::get_last(), Aleph::DynList< T >::get_last(), Aleph::QuickHull::get_right_points(), Aleph::Find_Eulerian_Path< GT, SN, SA >::hierholzer_directed(), Aleph::Find_Eulerian_Path< GT, SN, SA >::hierholzer_undirected(), Aleph::in_place_transpose(), Aleph::insert_sorted(), Aleph::AdversarialTraceCollector< Move, Score >::is_empty(), Aleph::DynListQueue< T >::is_empty(), Aleph::DynListStack< T >::is_empty(), Aleph::FlowPath< Net >::is_empty(), Moved_From_Case< Collector >::is_empty(), Moved_From_Case< DynSkipList< int > >::is_empty(), Moved_From_Case< Euler_Tour_LCA< int > >::is_empty(), Moved_From_Case< Binary_Lifting_LCA< Graph > >::is_empty(), Moved_From_Case< Euler_RMQ_LCA< Graph > >::is_empty(), Aleph::HTList::Iterator::is_in_first(), Aleph::HTList::Iterator::is_last(), QuadTree::join(), main(), Aleph::merge_lists(), Aleph::BruteForceConvexHull::operator()(), Aleph::GiftWrappingConvexHull::operator()(), Aleph::QuickHull::operator()(), Aleph::ShortestPathInPolygon::operator()(), Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::operator()(), Aleph::Dlink::operator=(), pop(), Aleph::QuickHull::quick_hull(), Aleph::quicksort(), Aleph::sort_utils_detail::radix_sort_impl(), Aleph::DynList< T >::remove(), remove(), remove_all_and_delete(), remove_head(), Aleph::HTList::Iterator::reset_last(), reverse(), rotate_left(), Aleph::Dial_Min_Paths< GT, Distance, Itor, SA >::run_dial(), Aleph::search_extreme(), Aleph::search_extreme(), Aleph::detail::shortest_path_portals(), Aleph::DynList< T >::size(), QuadTree::split(), Aleph::DynDlist< T >::split_list(), split_list(), Aleph::Dlink::split_list_ne(), Aleph::DynList< T >::split_list_ne(), Aleph::detail::spp_find_sleeve(), Aleph::k_shortest_paths_detail::state_to_path(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), top(), Aleph::transpose(), Aleph::Gen_Polynomial< Coefficient >::try_extract_primitive_cubic_factor(), Aleph::Gen_Polynomial< Coefficient >::try_extract_primitive_quadratic_factor(), TYPED_TEST(), TYPED_TEST(), TYPED_TEST(), TYPED_TEST(), Moved_From_Case< DynSkipList< int > >::use(), and Moved_From_Case< Euler_RMQ_LCA< Graph > >::use().

◆ is_unitarian()

bool Aleph::HTList::is_unitarian ( ) const
inlinenoexcept

Return true if the list contains exactly just one.

Definition at line 441 of file htlist.H.

References Aleph::and, head, and tail.

Referenced by split_list(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST_F().

◆ is_unitarian_or_empty()

bool Aleph::HTList::is_unitarian_or_empty ( ) const
inlinenoexcept

Return true if list contains one element or is empty.

Definition at line 448 of file htlist.H.

References head, and tail.

Referenced by Aleph::quicksort(), TEST(), TEST(), TEST(), and TEST().

◆ pop()

Slinknc * Aleph::HTList::pop ( )
inline

Remove the first item of this.

See also
remove_head()

This synonym is adequate when this is dealed as a stack.

Returns
a pointer to the removed item.
Exceptions
underflow_errorif the list is empty

Definition at line 733 of file htlist.H.

References ah_underflow_error_if, is_empty(), and remove_head().

Referenced by TEST(), TEST(), and TEST().

◆ push()

void Aleph::HTList::push ( Slinknc *  link)
inlinenoexcept

Definition at line 717 of file htlist.H.

References insert().

Referenced by TEST(), and TEST().

◆ put()

void Aleph::HTList::put ( Slinknc *  link)
inlinenoexcept

Definition at line 553 of file htlist.H.

References append().

Referenced by TEST().

◆ remove()

bool Aleph::HTList::remove ( Slinknc *  link)
inline
 Remove from the list the item pointed by `link`

remove(link) perform a sequential traversal of this until find link. Then link is removed.

This method has a complexity of \(O(n)\) for worst and average case.

Parameters
[in]linkpointer to the item to be removed.
Returns
true if link was found and removed: false otherwise
Exceptions
underflow_errorif the list is empty

Definition at line 691 of file htlist.H.

References ah_underflow_error_if, head, is_empty(), NEXT, Aleph::Slinknc::reset(), and tail.

Referenced by TEST().

◆ remove_all_and_delete()

void Aleph::HTList::remove_all_and_delete ( )
inlinenoexcept
Remove and free memory for all the items of list.

remove_all_and_delete() remove each item of the list and call to delete operator on the removed item. At the end of call, all the items were removed, all the memory freed qand the list emptied.

Warning
This method only has sense if the items of list were dynamically allocated with new. Although That is very frequently the case, there are some exceptions. So, be sure that the items were allocated with new operator.

Definition at line 879 of file htlist.H.

References is_empty(), and remove_head_ne().

Referenced by List_of_25_nodes::~List_of_25_nodes(), main(), HTListInsertBugFixTest::TearDown(), HTListSplitTest::TearDown(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST_F().

◆ remove_first()

Slinknc * Aleph::HTList::remove_first ( )
inline

Definition at line 672 of file htlist.H.

References remove_head().

Referenced by main(), rotate_left(), and TEST().

◆ remove_first_ne()

Slinknc * Aleph::HTList::remove_first_ne ( )
inlinenoexcept

Remove the header item from the list.

See also
remove_head()
Returns
a pointer to the removed item
Precondition
the list is not empty

Definition at line 667 of file htlist.H.

References remove_head_ne().

Referenced by Aleph::HTList::Iterator::del_ne(), Aleph::quicksort(), and reverse().

◆ remove_head()

Slinknc * Aleph::HTList::remove_head ( )
inline

Remove the header item from the list.

Returns
a pointer to the removed item
Exceptions
underflow_errorif the list is empty

Definition at line 652 of file htlist.H.

References ah_underflow_error_if, is_empty(), and remove_head_ne().

Referenced by pop(), Aleph::DynList< T >::remove(), remove_first(), and Aleph::DynList< T >::remove_head().

◆ remove_head_ne()

Slinknc * Aleph::HTList::remove_head_ne ( )
inlinenoexcept

It deletes head element (first one). Return deleted.

Definition at line 630 of file htlist.H.

References head, NEXT, Aleph::Slinknc::reset(), and tail.

Referenced by remove_all_and_delete(), remove_first_ne(), remove_head(), Aleph::DynList< T >::remove_head_ne(), and Aleph::DynList< T >::remove_ne().

◆ reset()

void Aleph::HTList::reset ( )
inlinenoexcept

Definition at line 429 of file htlist.H.

References head, and tail.

Referenced by Aleph::DynList< T >::empty(), and Aleph::DynList< T >::reset().

◆ reverse()

size_t Aleph::HTList::reverse ( )
inlinenoexcept

It inverts all list elements. It returns list size.

Definition at line 816 of file htlist.H.

References Aleph::count(), insert(), is_empty(), remove_first_ne(), and swap().

Referenced by main(), reverse_list(), TEST(), TEST(), and TEST().

◆ reverse_list()

size_t Aleph::HTList::reverse_list ( )
inlinenoexcept

See reverse().

Definition at line 833 of file htlist.H.

References reverse().

Referenced by Aleph::DynList< T >::reverse(), TEST(), and TEST().

◆ rotate_left()

void Aleph::HTList::rotate_left ( size_t  n)
inline

Rotate to left the list n positions.

rotate_left(n) rotates the items to left n positions. For example, if the list is as follows:

l0, l1, l2, l3, l4, l5, l6, l7, l8, l9

Then rotate_left(4) produces the following state:

l4, l5, l6, l7, l8, l9, l0, l1, l2, l3
Parameters
[in]nthe number of position to be rotated
Exceptions
domain_errorif list is empty

Definition at line 1144 of file htlist.H.

References ah_domain_error, append(), is_empty(), and remove_first().

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().

◆ size()

size_t Aleph::HTList::size ( ) const
inlinenoexcept

Count the number of elements of the list.

This method counts, it does not retrieve, the number of elements stored in the list, so that its complexity is \(O(n)\). HTList does not keep a counter, because items can be added or removed through a node, without the list. DynList, whose items change through its own operations, keeps one, and its size() is \(O(1)\).

Returns
the number of items of list

Definition at line 1119 of file htlist.H.

References Aleph::count(), and Aleph::HTList::Iterator::has_curr().

Referenced by TEST(), TEST(), and TEST().

◆ split()

size_t Aleph::HTList::split ( HTList &  l,
HTList &  r 
)
inlinenoexcept

See split_list(HTList & l, HTList & r).

Definition at line 809 of file htlist.H.

References l, r, and split_list().

◆ split_list()

size_t Aleph::HTList::split_list ( HTList &  l,
HTList &  r 
)
inlinenoexcept

It divides 'this' into two equal lists without modifying.

Split the list in two.

This method takes the first n/2 items of this and puts them, in the same order, in list l. The remainder items are put in list r. After operation this becomes empty. The order of items is preserved through l and r.

Parameters
[out]llist containg the first n - n/2 items
[out]rlist containg the last n/2 items
Returns
the number of items that this had

Definition at line 760 of file htlist.H.

References Aleph::and, Aleph::count(), head, is_empty(), is_unitarian(), l, NEXT, r, swap(), and tail.

Referenced by main(), split(), and split_list_ne().

◆ split_list_ne()

size_t Aleph::HTList::split_list_ne ( HTList &  l,
HTList &  r 
)
inlinenoexcept

Definition at line 803 of file htlist.H.

References l, r, and split_list().

Referenced by TEST().

◆ swap()

HTList & Aleph::HTList::swap ( HTList &  l)
inlinenoexcept
 \brief  Swap in constant time (very fast) 'this' elements with 'l'

list elements
Referenced by append(), insert(), reverse() and split_list().

Parameters
[in]lNew list which elements will be exchanged

Definition at line 488 of file htlist.H.

References head, l, and tail.

Referenced by append(), insert(), reverse(), split_list(), Aleph::DynList< T >::split_list_ne(), Aleph::DynList< T >::swap(), and TEST_F().

◆ top()

Slinknc * Aleph::HTList::top ( ) const
inline

Definition at line 739 of file htlist.H.

References ah_underflow_error_if, get_first(), and is_empty().

Referenced by TEST(), TEST(), and TEST().

Member Data Documentation

◆ head

◆ tail


The documentation for this class was generated from the following file: