FreeNOS
Public Member Functions
Associative< K, V > Class Template Referenceabstract

Associatives are containers that provide a mapping of keys to values. More...

#include <Associative.h>

Inheritance diagram for Associative< K, V >:
Container Comparable< Associative< K, V > > HashTable< K, V >

Public Member Functions

virtual bool insert (const K &key, const V &item)
 Inserts the given item to the Assocation. More...
 
virtual bool append (const K &key, const V &item)
 Append the given item to the Association. More...
 
virtual int remove (const K &key)
 Removes all items associated with the given key. More...
 
virtual void clear ()
 Removes all items from the Association. More...
 
virtual List< K > keys () const =0
 Retrieve all keys inside the Association. More...
 
virtual List< K > keys (const V &value) const =0
 Retrieve list of Keys for the given value. More...
 
virtual bool contains (const K &key) const
 Check if the given key exists. More...
 
virtual List< V > values () const =0
 Retrieve all values inside the Association. More...
 
virtual List< V > values (const K &key) const =0
 Retrieve values for the given key inside the Association. More...
 
virtual const V * get (const K &key) const =0
 Returns the first value for the given key. More...
 
virtual const V & at (const K &key) const =0
 Returns a reference to the first value for the given key. More...
 
virtual const V value (const K &key, const V defaultValue=V()) const =0
 Return the first value for the given key. More...
 
virtual int compareTo (const Associative< K, V > &a) const
 Compare this instance to another instance. More...
 
virtual bool equals (const Associative< K, V > &a) const
 Test if an Associative is equal to an other Associative. More...
 
const V & operator[] (K key) const
 Returns the first value for the given key. More...
 
- Public Member Functions inherited from Container
 Container ()
 Constructor. More...
 
virtual ~Container ()
 Destructor. More...
 
virtual Size size () const =0
 Returns the maximum size of this Container. More...
 
virtual Size count () const =0
 Returns the number of items inside the Container. More...
 
virtual bool isEmpty () const
 Check if the Container is empty. More...
 
virtual bool reserve (Size size)
 Ensure that at least the given size is available. More...
 
virtual bool shrink (Size size)
 Shrink the container size by the given amount of items. More...
 
virtual Size squeeze ()
 Try to minimize the memory required in the Container. More...
 
virtual bool resize (Size size)
 Change the size of the Container. More...
 
- Public Member Functions inherited from Comparable< Associative< K, V > >
virtual ~Comparable ()
 Class destructor. More...
 

Detailed Description

template<class K, class V>
class Associative< K, V >

Associatives are containers that provide a mapping of keys to values.

Definition at line 39 of file Associative.h.

Member Function Documentation

◆ append()

template<class K , class V >
virtual bool Associative< K, V >::append ( const K &  key,
const V &  item 
)
inlinevirtual

◆ at()

template<class K , class V >
virtual const V& Associative< K, V >::at ( const K &  key) const
pure virtual

◆ clear()

template<class K , class V >
virtual void Associative< K, V >::clear ( )
inlinevirtual

Removes all items from the Association.

Implements Container.

Definition at line 86 of file Associative.h.

◆ compareTo()

template<class K , class V >
virtual int Associative< K, V >::compareTo ( const Associative< K, V > &  a) const
inlinevirtual

Compare this instance to another instance.

Parameters
aOther instance to compare to
Returns
Zero if equal, non-zero otherwise

Implements Comparable< Associative< K, V > >.

Definition at line 169 of file Associative.h.

Referenced by Associative< String, FileCache * >::equals().

◆ contains()

template<class K , class V >
virtual bool Associative< K, V >::contains ( const K &  key) const
inlinevirtual

Check if the given key exists.

Returns
True if exists, false otherwise.

Definition at line 111 of file Associative.h.

Referenced by FileSystemServer::findFileCache(), LinnFileSystem::getInode(), and FileSystemServer::lookupFile().

◆ equals()

template<class K , class V >
virtual bool Associative< K, V >::equals ( const Associative< K, V > &  a) const
inlinevirtual

Test if an Associative is equal to an other Associative.

Parameters
aAssociative instance.
Returns
True if equal, false otherwise.

Implements Comparable< Associative< K, V > >.

Definition at line 198 of file Associative.h.

◆ get()

template<class K , class V >
virtual const V* Associative< K, V >::get ( const K &  key) const
pure virtual

◆ insert()

template<class K , class V >
virtual bool Associative< K, V >::insert ( const K &  key,
const V &  item 
)
inlinevirtual

Inserts the given item to the Assocation.

If an item exists for the given key, its value will be replaced.

Parameters
keyThe key of the item to insert
itemThe item to insert
Returns
bool Whether inserting the item at the given position succeeded.

Reimplemented in HashTable< u32, LinnInode * >, HashTable< u32, File * >, HashTable< u16, UDPSocket * >, HashTable< String, ShellCommand * >, HashTable< String, FileCache * >, HashTable< String, Argument * >, HashTable< ProcessID, HashTable< String, Address > * >, HashTable< ProcessID, Channel * >, HashTable< K, V >, and HashTable< IPV4::Address, ARP::ARPCache * >.

Definition at line 53 of file Associative.h.

◆ keys() [1/2]

template<class K , class V >
virtual List<K> Associative< K, V >::keys ( ) const
pure virtual

◆ keys() [2/2]

template<class K , class V >
virtual List<K> Associative< K, V >::keys ( const V &  value) const
pure virtual

◆ operator[]()

template<class K , class V >
const V& Associative< K, V >::operator[] ( key) const
inline

Returns the first value for the given key.

If there are multiple values for the key, the first value is returned.

Parameters
keyThe key of the item to return.
Returns
The first value for the key.

Definition at line 213 of file Associative.h.

◆ remove()

template<class K , class V >
virtual int Associative< K, V >::remove ( const K &  key)
inlinevirtual

◆ value()

template<class K , class V >
virtual const V Associative< K, V >::value ( const K &  key,
const V  defaultValue = V() 
) const
pure virtual

Return the first value for the given key.

If the key is not found, the default value is returned.

Parameters
keyKey to find value for
defaultValueReturn this default value if not found
Returns
First value for the given key, or the defaultValue.

Implemented in HashTable< u32, LinnInode * >, HashTable< u32, File * >, HashTable< u16, UDPSocket * >, HashTable< String, ShellCommand * >, HashTable< String, FileCache * >, HashTable< String, Argument * >, HashTable< ProcessID, HashTable< String, Address > * >, HashTable< ProcessID, Channel * >, HashTable< K, V >, and HashTable< IPV4::Address, ARP::ARPCache * >.

◆ values() [1/2]

template<class K , class V >
virtual List<V> Associative< K, V >::values ( ) const
pure virtual

◆ values() [2/2]

template<class K , class V >
virtual List<V> Associative< K, V >::values ( const K &  key) const
pure virtual

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