Rudiments
Public Member Functions | List of all members
singlylinkedlist< valuetype > Class Template Reference

Inherits listcollection< valuetype >.

Public Member Functions

 singlylinkedlist ()
 
 singlylinkedlist (singlylinkedlist< valuetype > &a)
 
 singlylinkedlist (listcollection< valuetype > &a)
 
singlylinkedlist< valuetype > & operator= (singlylinkedlist< valuetype > &a)
 
singlylinkedlist< valuetype > & operator= (nodecollection< valuetype > &a)
 
 ~singlylinkedlist ()
 
void prepend (valuetype value)
 
void prepend (listnode< valuetype > *node)
 
void append (valuetype value)
 
void append (listnode< valuetype > *node)
 
void insertAfter (listnode< valuetype > *node, valuetype value)
 
void insertAfter (listnode< valuetype > *node, listnode< valuetype > *newnode)
 
void moveAfter (listnode< valuetype > *node, listnode< valuetype > *nodetomove)
 
void detach (listnode< valuetype > *node)
 
bool remove (valuetype value)
 
bool removeAll (valuetype value)
 
bool remove (listnode< valuetype > *node)
 
uint64_t getCount ()
 
listnode< valuetype > * getFirst ()
 
listnode< valuetype > * getLast ()
 
listnode< valuetype > * getNext (listnode< valuetype > *node)
 
listnode< valuetype > * find (valuetype value)
 
listnode< valuetype > * find (listnode< valuetype > *startnode, valuetype value)
 
void sortInexpensively ()
 
void sortQuickly ()
 
bool clear ()
 
- Public Member Functions inherited from listcollection< valuetype >
 listcollection ()
 
 listcollection (nodecollection< valuetype > &n)
 
virtual const char * getType ()
 
virtual void prepend (valuetype *values, uint64_t count)
 
virtual void append (valuetype *values, uint64_t count)
 
virtual void insertBefore (listnode< valuetype > *node, valuetype value)=0
 
virtual void insertBefore (listnode< valuetype > *node, valuetype *values, uint64_t count)
 
virtual void insertBefore (listnode< valuetype > *node, listnode< valuetype > *newnode)=0
 
virtual void insertAfter (listnode< valuetype > *node, valuetype *values, uint64_t count)
 
virtual void moveBefore (listnode< valuetype > *node, listnode< valuetype > *nodetomove)=0
 
virtual ssize_t write ()
 
virtual ssize_t write (output *out)
 
virtual ssize_t writeJson ()
 
virtual ssize_t writeJson (bool indent)
 
virtual ssize_t writeJson (output *out)
 
virtual ssize_t writeJson (output *out, bool indent)
 
- Public Member Functions inherited from collection
 collection ()
 
 collection (collection &c)
 
collectionoperator= (collection &c)
 
virtual ~collection ()
 
comparatorgetComparator ()
 
void setComparator (comparator *newcomp)
 
virtual bool isReadOnly ()
 
virtual bool isBlockBased ()
 
virtual uint64_t getBlockSize ()
 
virtual bool isSequentialAccess ()
 
virtual void setManageValues (bool manage)
 
virtual bool getManageValues ()
 
virtual void setManageArrayValues (bool manage)
 
virtual bool getManageArrayValues ()
 
virtual void setManageKeys (bool manage)
 
virtual bool getManageKeys ()
 
virtual void setManageArrayKeys (bool manage)
 
virtual bool getManageArrayKeys ()
 
- Public Member Functions inherited from object
virtual ~object ()
 

Detailed Description

template<class valuetype>
class singlylinkedlist< valuetype >

The singlylinkedlist class allows you to store an arbitrary number of values in a singly-linked list. Since the singlylinkedlist class is template-based, you can store arbitrary types of values.

Each singlylinkedlist is composed of a series of singlylinkedlistnodes. Each singlylinkedlistnode contains a value.

This class is similar to the linkedlist class but uses less memory and many of its operations are faster.

However, the move, detach and remove operations are much slower. If your application must run these operations regularly, you should consider using the linkedlist class instead.

Constructor & Destructor Documentation

◆ singlylinkedlist() [1/3]

template<class valuetype >
singlylinkedlist< valuetype >::singlylinkedlist
inline

Creates an empty instance of the singlylinkedlist class.

◆ singlylinkedlist() [2/3]

template<class valuetype >
singlylinkedlist< valuetype >::singlylinkedlist ( singlylinkedlist< valuetype > &  a)
inline

Creates an instance of the singlylinkedlist class that is a copy of "a".

◆ singlylinkedlist() [3/3]

template<class valuetype >
singlylinkedlist< valuetype >::singlylinkedlist ( listcollection< valuetype > &  a)
inline

Creates an instance of the singlylinkedlist class that is a copy of "a".

◆ ~singlylinkedlist()

template<class valuetype >
singlylinkedlist< valuetype >::~singlylinkedlist
inline

Deletes this instance of the singlylinkedlist class and all of its singlylinkedlistnodes.

The value stored in each singlylinkedlistnode is only deleted if setManageValues(true) or setManageArrayValues(true) has been called.

Member Function Documentation

◆ append() [1/2]

template<class valuetype >
void singlylinkedlist< valuetype >::append ( listnode< valuetype > *  node)
inlinevirtual

Appends already created singlylinkedlistnode "node" to the singlylinkedlist.

Implements listcollection< valuetype >.

◆ append() [2/2]

template<class valuetype >
void singlylinkedlist< valuetype >::append ( valuetype  value)
inlinevirtual

Creates a new singlylinkedlistnode containing "value" and appends it to the singlylinkedlist.

Implements listcollection< valuetype >.

◆ clear()

template<class valuetype >
bool singlylinkedlist< valuetype >::clear
inlinevirtual

Deletes all singlylinkedlistnodes currently in the singlylinkedlist.

The value stored in each singlylinkedlistnode is only deleted if setManageValues(true) or setManageArrayValues(true) has been called.

Always returns true.

Implements collection.

◆ detach()

template<class valuetype >
void singlylinkedlist< valuetype >::detach ( listnode< valuetype > *  node)
inlinevirtual

Detaches "node" from the list.

Note that this operation requires a search and is expensive in both execution time and code size. Consider using the linkedlist class.

Implements listcollection< valuetype >.

◆ find() [1/2]

template<class valuetype >
listnode< valuetype > * singlylinkedlist< valuetype >::find ( listnode< valuetype > *  startnode,
valuetype  value 
)
inlinevirtual

Returns a pointer to the first singlylinkedlistnode after "startnode" containing "value" or NULL if "value" was not found.

Implements listcollection< valuetype >.

◆ find() [2/2]

template<class valuetype >
listnode< valuetype > * singlylinkedlist< valuetype >::find ( valuetype  value)
inlinevirtual

Returns a pointer to the first singlylinkedlistnode containing "value" or NULL if "value" was not found.

Implements listcollection< valuetype >.

◆ getCount()

template<class valuetype >
uint64_t singlylinkedlist< valuetype >::getCount
inlinevirtual

Returns the number of nodes in the singlylinkedlist.

Implements collection.

◆ getFirst()

template<class valuetype >
listnode< valuetype > * singlylinkedlist< valuetype >::getFirst
inlinevirtual

Returns the first node in the singlylinkedlist.

Implements listcollection< valuetype >.

◆ getLast()

template<class valuetype >
listnode< valuetype > * singlylinkedlist< valuetype >::getLast
inline

Returns the last node in the singlylinkedlist.

◆ getNext()

template<class valuetype >
listnode< valuetype > * singlylinkedlist< valuetype >::getNext ( listnode< valuetype > *  node)
inlinevirtual

Returns the node after "node" or NULL if this node is the last node in the list. "node" is presumed to be in the list.

Implements listcollection< valuetype >.

◆ insertAfter() [1/2]

template<class valuetype >
void singlylinkedlist< valuetype >::insertAfter ( listnode< valuetype > *  node,
listnode< valuetype > *  newnode 
)
inlinevirtual

Inserts already created singlylinkedlistnode "node" into the singlylinkedlist after "node".

Implements listcollection< valuetype >.

◆ insertAfter() [2/2]

template<class valuetype >
void singlylinkedlist< valuetype >::insertAfter ( listnode< valuetype > *  node,
valuetype  value 
)
inlinevirtual

Creates a new singlylinkedlistnode containing "value" and inserts it into the singlylinkedlist after "node".

Implements listcollection< valuetype >.

◆ moveAfter()

template<class valuetype >
void singlylinkedlist< valuetype >::moveAfter ( listnode< valuetype > *  node,
listnode< valuetype > *  nodetomove 
)
inlinevirtual

Moves node "nodetomove" to the position after "node" in the singlylinkedlist.

Note that this operation requires a search and is expensive in both execution time and code size. Consider using the linkedlist class.

Implements listcollection< valuetype >.

◆ operator=() [1/2]

template<class valuetype >
singlylinkedlist< valuetype > & singlylinkedlist< valuetype >::operator= ( nodecollection< valuetype > &  a)
inline

Makes this instance of the singlylinkedlist class identical to "a".

◆ operator=() [2/2]

template<class valuetype >
singlylinkedlist< valuetype > & singlylinkedlist< valuetype >::operator= ( singlylinkedlist< valuetype > &  a)
inline

Makes this instance of the singlylinkedlist class identical to "a".

◆ prepend() [1/2]

template<class valuetype >
void singlylinkedlist< valuetype >::prepend ( listnode< valuetype > *  node)
inlinevirtual

Prepends already created singlylinkedlistnode "node" to the singlylinkedlist.

Implements listcollection< valuetype >.

◆ prepend() [2/2]

template<class valuetype >
void singlylinkedlist< valuetype >::prepend ( valuetype  value)
inlinevirtual

Creates a new singlylinkedlistnode containing "value" and prepends it to the singlylinkedlist.

Implements listcollection< valuetype >.

◆ remove() [1/2]

template<class valuetype >
bool singlylinkedlist< valuetype >::remove ( listnode< valuetype > *  node)
inlinevirtual

Removes singlylinkedlistnode "node" from the singlylinkedlist.

The value stored in the singlylinkedlistnode is only deleted if setManageValues(true) or setManageArrayValues(true) has been called.

Note that this operation requires a search and is expensive in both execution time and code size. Consider using the linkedlist class.

Returns true on success and false on failure.

Implements listcollection< valuetype >.

◆ remove() [2/2]

template<class valuetype >
bool singlylinkedlist< valuetype >::remove ( valuetype  value)
inlinevirtual

Deletes the first singlylinkedlistnode containing "value".

The value stored in the singlylinkedlistnode is only deleted if setManageValues(true) or setManageArrayValues(true) has been called.

Note that this operation requires a search and is expensive in both execution time and code size. Consider using the linkedlist class.

Returns true on success and false on failure.

Implements listcollection< valuetype >.

◆ removeAll()

template<class valuetype >
bool singlylinkedlist< valuetype >::removeAll ( valuetype  value)
inlinevirtual

Deletes all singlylinkedlistnodes containing "value".

The value stored in each singlylinkedlistnode is only deleted if setManageValues(true) or setManageArrayValues(true) has been called.

Note that this operation requires a search and is expensive in both execution time and code size. Consider using the linkedlist class.

Returns true on success and false on failure.

Implements listcollection< valuetype >.

◆ sortInexpensively()

template<class valuetype >
void singlylinkedlist< valuetype >::sortInexpensively
inlinevirtual

Sorts the listcollection.

This sort is potentially much slower than sortQuickly() but uses no additional memory.

The order that the items are sorted into depends on the comparator that is being used, and how that comparator is configured. The default comparator, in its default configuration causes the list to be sorted in ascending order.

See collection::setComparator() and the comparator class for more detail.

Implements listcollection< valuetype >.

◆ sortQuickly()

template<class valuetype >
void singlylinkedlist< valuetype >::sortQuickly
inlinevirtual

Sorts the listcollection.

This sort is potentially much faster than sortInexpensively() but uses additional memory in proportion to the size of the list.

The order that the items are sorted into depends on the comparator that is being used, and how that comparator is configured. The default comparator, in its default configuration causes the list to be sorted in ascending order.

See collection::setComparator() and the comparator class for more detail.

Implements listcollection< valuetype >.