feisty meow concerns codebase  2.140
structures::set< contents > Class Template Reference

Emulates a mathematical set, providing several standard set operations. More...

#include <set.h>

Inheritance diagram for structures::set< contents >:
Collaboration diagram for structures::set< contents >:

Public Member Functions

 set (int num=0, const contents *init=NULL_POINTER, basis::un_short flags=basis::array< contents >::EXPONE)
 Constructs a set with "num" elements, copying them from "init". More...
 
 ~set ()
 Destroys any storage held for the set. More...
 
int elements () const
 Returns the number of elements in this set. More...
 
bool empty () const
 Returns true if the set has no elements. More...
 
bool non_empty () const
 Returns true if the set has some elements. More...
 
void clear ()
 Empties out this set. More...
 
bool member (const contents &to_test) const
 Returns true if the item "to_test" is a member of this set. More...
 
bool add (const contents &to_add)
 Adds a new element "to_add" to the set. More...
 
setoperator+= (const contents &to_add)
 An algebraic operator synonym for add() that operates on the contents. More...
 
setoperator+= (const set &to_add)
 An algebraic operator synonym for add() that operates on a set. More...
 
bool remove (const contents &to_remove)
 Removes the item "to_remove" from the set. More...
 
setoperator-= (const contents &to_zap)
 An algebraic operator synonym for remove that operates on the contents. More...
 
setoperator-= (const set &to_zap)
 An algebraic operator synonym for remove that operates on a set. More...
 
set set_union (const set &union_with) const
 Implements the set union of "this" with "union_with". More...
 
void unionize (const set &union_with)
 Makes "this" set a union of "this" and "union_with". More...
 
set operator+ (const set &uw) const
 A synonym for set_union. More...
 
set intersection (const set &intersect_with) const
 Returns the intersection of "this" with the set in "intersect_with". More...
 
set operator* (const set &iw) const
 A synonym for intersection. More...
 
set difference (const set &differ_with) const
 Returns the difference of this with "differ_with". More...
 
void differentiate (const set &differ_with)
 Makes "this" set equal to the difference of "this" and "differ_with". More...
 
set operator- (const set &dw) const
 A synonym for difference. More...
 
int find (const contents &to_find) const
 Returns the integer index of the item "to_find" in this set. More...
 
bool remove_index (int index)
 Zaps the entry at the specified "index". More...
 
- Public Member Functions inherited from basis::array< contents >
 DEFINE_CLASS_NAME ("array")
 
 array (int number=0, const contents *init=NULL_POINTER, int flags=EXPONENTIAL_GROWTH|FLUSH_INVISIBLE)
 Constructs an array with room for "number" objects. More...
 
 array (const array< contents > &copy_from)
 copies the contents & sizing information from "copy_from". More...
 
virtual ~array ()
 destroys the memory allocated for the objects. More...
 
void reset (int number=0, const contents *initial_contents=NULL_POINTER)
 Resizes this array and sets the contents from an array of contents. More...
 
arrayoperator= (const array< contents > &copy_from)
 Copies the array in "copy_from" into this. More...
 
int length () const
 Returns the current reported length of the allocated C array. More...
 
int last () const
 Returns the last valid element in the array. More...
 
int flags () const
 Provides the raw flags value, without interpreting what it means. More...
 
bool exponential () const
 Returns true if this allocator will grow exponentially on resize. More...
 
bool simple () const
 Reports whether the templated object is a simple type or not. More...
 
const contents & get (int index) const
 Accesses individual objects stored in "this" at the "index" position. More...
 
contents & use (int index)
 A non-constant version of get(); the returned object can be modified. More...
 
const contents & operator[] (int index) const
 Synonym for get that provides the expected array indexing syntax. More...
 
contents & operator[] (int index)
 Synonym for use that provides the expected array indexing syntax. More...
 
outcome put (int index, const contents &to_put)
 Stores an object at the index "index" in the array. More...
 
array concatenation (const array &to_concatenate) const
 Returns the concatenation of "this" and the array "to_concatenate". More...
 
array concatenation (const contents &to_concatenate) const
 Returns the concatenation of "this" and the object "to_concatenate". More...
 
arrayconcatenate (const array &to_concatenate)
 Appends the array "to_concatenate" onto "this" and returns "this". More...
 
arrayconcatenate (const contents &to_concatenate)
 Appends the object "to_concatenate" onto "this" and returns "this". More...
 
arrayconcatenate (const contents *to_concatenate, int length)
 Concatenates a C-array "to_concatenate" onto "this" and returns "this". More...
 
array operator+ (const array &to_cat) const
 Synonym for concatenation. More...
 
array operator+ (const contents &to_concatenate) const
 Synonym for concatenation. More...
 
arrayoperator+= (const array &to_concatenate)
 Synonym for concatenate that modifies "this". More...
 
arrayoperator+= (const contents &to_concatenate)
 Synonym for concatenate that modifies "this". More...
 
const contents * observe () const
 Returns a pointer to the underlying C array of data. More...
 
contents * access ()
 A non-constant access of the underlying C-array. BE REALLY CAREFUL. More...
 
void swap_contents (array< contents > &other)
 Exchanges the contents of "this" and "other". More...
 
void snarf (array &new_contents)
 Drops "this" array's contents into the dustbin and uses "new_contents". More...
 
array subarray (int start, int end) const
 Returns the array segment between the indices "start" and "end". More...
 
outcome insert (int index, int new_indices)
 Adds "new_indices" new positions for objects into the array at "index". More...
 
outcome overwrite (int index, const array &write_with, int count=-1)
 Stores the array "write_with" into the current array at the "index". More...
 
outcome stuff (int length, contents *to_stuff) const
 Copies at most "length" elements from this into the array "to_stuff". More...
 
outcome resize (int new_size, how_to_copy way=NEW_AT_END)
 Changes the size of the C array to "new_size". More...
 
outcome zap (int start, int end)
 Deletes from "this" the objects inclusively between "start" and "end". More...
 
outcome shrink ()
 Cuts loose any allocated space that is beyond the real length. More...
 
outcome retrain (int new_size, const contents *to_copy)
 Resizes the C array and stuffs it with the contents in "to_copy". More...
 
void shift_data (shift_directions where)
 The valid portion of the array is moved to the left or right. More...
 
int internal_real_length () const
 Gritty Internal: the real allocated length. More...
 
int internal_offset () const
 Gritty Internal: the offset from real start to stored data. More...
 
const contents * internal_block_start () const
 Gritty Internal: constant peek at the real allocated pointer. More...
 
contents * internal_block_start ()
 Gritty Internal: the real allocated pointer made accessible. More...
 
contents *const * internal_offset_mem () const
 Gritty Internal: the start of the actual stored data. More...
 

Additional Inherited Members

- Public Types inherited from basis::array< contents >
enum  specialc_flags {
  NO_SPECIAL_MODES = 0x0 , SIMPLE_COPY = 0x1 , EXPONENTIAL_GROWTH = 0x2 , EXPONE = EXPONENTIAL_GROWTH ,
  FLUSH_INVISIBLE = 0x4
}
 the flags specify how the array treats its contents and its length. More...
 
enum  how_to_copy { NEW_AT_END , NEW_AT_BEGINNING , DONT_COPY }
 
enum  shift_directions { TO_LEFT , TO_RIGHT }
 

Detailed Description

template<class contents>
class structures::set< contents >

Emulates a mathematical set, providing several standard set operations.

Note: this is not an efficient object and it should not be used for sets of non-trivial sizes.

Definition at line 35 of file set.h.

Constructor & Destructor Documentation

◆ set()

template<class contents >
structures::set< contents >::set ( int  num = 0,
const contents *  init = NULL_POINTER,
basis::un_short  flags = basis::array<contents>::EXPONE 
)
inline

Constructs a set with "num" elements, copying them from "init".

Be very careful to ensure that the array "init" has sufficient length for "num" elements to be copied from it.

Definition at line 41 of file set.h.

◆ ~set()

template<class contents >
structures::set< contents >::~set ( )
inline

Destroys any storage held for the set.

Definition at line 45 of file set.h.

Member Function Documentation

◆ add()

template<class contents >
bool structures::set< contents >::add ( const contents &  to_add)

Adds a new element "to_add" to the set.

This always succeeds, but will return true if the item was not already present.

Definition at line 232 of file set.h.

Referenced by processes::process_control::find_process_in_list(), textual::list_parsing::get_ids_from_string(), structures::set< contents >::operator+=(), structures::set< contents >::set_union(), and structures::unpack().

◆ clear()

template<class contents >
void structures::set< contents >::clear ( )
inline

◆ difference()

template<class contents >
set< contents > structures::set< contents >::difference ( const set< contents > &  differ_with) const

Returns the difference of this with "differ_with".

Difference is defined as the subset of elements in "this" that are not also in "differ_with".

Definition at line 293 of file set.h.

References structures::set< contents >::elements(), structures::set< contents >::member(), and structures::set< contents >::remove().

Referenced by structures::set< contents >::operator-().

◆ differentiate()

template<class contents >
void structures::set< contents >::differentiate ( const set< contents > &  differ_with)

Makes "this" set equal to the difference of "this" and "differ_with".

That is, after the call, "this" will only contain elements that were not also in "differ_with".

Definition at line 304 of file set.h.

References structures::set< contents >::elements().

Referenced by structures::set< contents >::operator-=().

◆ elements()

◆ empty()

template<class contents >
bool structures::set< contents >::empty ( ) const
inline

Returns true if the set has no elements.

Definition at line 50 of file set.h.

References structures::set< contents >::elements().

◆ find()

template<class contents >
int structures::set< contents >::find ( const contents &  to_find) const

Returns the integer index of the item "to_find" in this set.

This returns a negative number if the index cannot be found. Note that this only makes sense within our particular implementation of set as an array.

Definition at line 240 of file set.h.

◆ intersection()

template<class contents >
set< contents > structures::set< contents >::intersection ( const set< contents > &  intersect_with) const

◆ member()

◆ non_empty()

template<class contents >
bool structures::set< contents >::non_empty ( ) const
inline

Returns true if the set has some elements.

Definition at line 52 of file set.h.

References structures::set< contents >::elements().

◆ operator*()

template<class contents >
set structures::set< contents >::operator* ( const set< contents > &  iw) const
inline

A synonym for intersection.

Definition at line 98 of file set.h.

References structures::set< contents >::intersection().

◆ operator+()

template<class contents >
set structures::set< contents >::operator+ ( const set< contents > &  uw) const
inline

A synonym for set_union.

Definition at line 92 of file set.h.

References structures::set< contents >::set_union().

◆ operator+=() [1/2]

template<class contents >
set& structures::set< contents >::operator+= ( const contents &  to_add)
inline

An algebraic operator synonym for add() that operates on the contents.

Definition at line 65 of file set.h.

References structures::set< contents >::add().

◆ operator+=() [2/2]

template<class contents >
set& structures::set< contents >::operator+= ( const set< contents > &  to_add)
inline

An algebraic operator synonym for add() that operates on a set.

Definition at line 68 of file set.h.

References structures::set< contents >::unionize().

◆ operator-()

template<class contents >
set structures::set< contents >::operator- ( const set< contents > &  dw) const
inline

A synonym for difference.

Definition at line 111 of file set.h.

References structures::set< contents >::difference().

◆ operator-=() [1/2]

template<class contents >
set& structures::set< contents >::operator-= ( const contents &  to_zap)
inline

An algebraic operator synonym for remove that operates on the contents.

Definition at line 76 of file set.h.

References structures::set< contents >::remove().

◆ operator-=() [2/2]

template<class contents >
set& structures::set< contents >::operator-= ( const set< contents > &  to_zap)
inline

An algebraic operator synonym for remove that operates on a set.

Definition at line 79 of file set.h.

References structures::set< contents >::differentiate().

◆ remove()

template<class contents >
bool structures::set< contents >::remove ( const contents &  to_remove)

Removes the item "to_remove" from the set.

If it was not present, false is returned and the set is unchanged.

Definition at line 249 of file set.h.

Referenced by structures::set< contents >::difference(), structures::set< contents >::operator-=(), and sockets::socket_minder::zap_pending_server().

◆ remove_index()

template<class contents >
bool structures::set< contents >::remove_index ( int  index)
inline

Zaps the entry at the specified "index".

This also treats the set like an array. The index must be within the bounds of the existing members.

Definition at line 123 of file set.h.

References basis::array< contents >::zap().

◆ set_union()

template<class contents >
set< contents > structures::set< contents >::set_union ( const set< contents > &  union_with) const

Implements the set union of "this" with "union_with".

This returns the set formed from the union of "this" set with the set specified in "union_with". (unfortunately, the name "set_union" must be used to distinguish from the C keyword "union".)

Definition at line 277 of file set.h.

References structures::set< contents >::add(), structures::set< contents >::elements(), and basis::array< contents >::get().

Referenced by structures::set< contents >::operator+().

◆ unionize()

template<class contents >
void structures::set< contents >::unionize ( const set< contents > &  union_with)

Makes "this" set a union of "this" and "union_with".

Definition at line 286 of file set.h.

References structures::set< contents >::elements(), and basis::array< contents >::get().

Referenced by structures::set< contents >::operator+=().


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