ADT Library


Contents

Introduction

As you are starting to read this, you first though might be - why write another class library? The answer is really simple. Every programmer has one since there is no accepted standard. My library uses templates, still a somewhat nonportable feature, but I believe they makes the code easier to read. I'll try to describe briefly the classes I have written and how one may use them. I'll also try to explain some design decisions I've made.

Main classes

The following is the available classes in a hierarchy. No, there is no single root, as I did not think it necessary. MFC-like approach uses the root class as the storage type for all container classes, which requires lots of casts in the code, which I really hate. All container classes are defined as templates (the T sign beside the name in the figure). Inheritance chains are designed to minimize code. For example, you may be tempted to base Vector on Array, but since most operations are identical to that of Matrix, it takes less code to do it this way. Feel free to tell me how wrong I am, and if you are convincing enough I'll change things around. Really!

Streamable
 |
 +--- Set (T)
 |     |
 |     +--- Array (T) 
 |     |     |
 |     |     +--- BitArray
 |     |
 |     +--- Array2d (T) 
 |           |
 |           +--- Matrix (T)
 |                 |
 |                 +--- Vector (T)
 |
 +--- CDate
 |
 +--- CString

Chain (T)
 |
 +--- LList (T)
 |     |
 |     +--- LCList (T)
 |
 +--- Stack (T)
 |
 +--- Queue (T)

HashTable (T)

CSocket
 |
 +--- CSocketServer
 |
 +--- CSocketClient

Descriptions of classes

For obvious reasons, I don't list overloaded functions twice. For example, if Set defines an operator =, and Array defines an operator =, and Array is derived from Set, I will not list operator= as present in Array since it will do the same thing as Set's operator does with an extension to class specific data. Another generic comment is that I make use of many assert statements. Compile the library and your program with a defined NDEBUG macro, and you'll get rid of those. That will of course make the program run faster.

Array

Include array.h to use. Array is a generic array template, derived from the generic container Set. I have decided that the difference would be only in order; i.e. in Set there is no way to reference any single element, as it has no position. The array does not grow and will give you a segmentation fault or an assert (without NDEBUG) if you try to reference outside bounds. The elements are stored in one contiguous chunk of allocated space, although it is probably a bad idea to rely on this. Array requires the element type to have defined comparison operators for sorting and searching (the latter not implemented yet). I have though about this and I can't think of a way to allow turning off those functions. No, I don't want to write a SortableArray class... Maybe a macro that you can define before including array.h? The function names, InsertAt and RemoveAt were borrowed from MFC library. You'll see some more MFC influence later. Array provides functions requiring the position of each element. The following functions are available:
Array (ArraySizeType nElem = 0)
Allocates nElem elements in the array. You may allocate zero entries too.
Array (const Array& AnArray)
Clones the array passed in.
Array (const ArrayEl * AnArray, ArraySizeType nElem)
Clones a normal C array As with Set, don't worry about the size types. They are usually integers, and I'll never make it something that can't treated as one.
ArrayEl& operator[] (ArraySizeType index) const
Returns a reference to the element at index. The call is declared as const, since it does not change the array internal data. The actual elements are not considered as data. Only their location is.
void InsertAt (ArraySizeType index, const ArrayEl& data)
Inserts a new element at given position (a copy operation), shifting the elements after index if necessary. The size of the array is increased by one.
void RemoveAt (ArraySizeType index)
Deletes the element at the specified location, shifting the elements after index if necessary. The size of the array decreased by one.
void Sort (int Start = 0, int End = -1)
Sorts the array using recursive quicksort. Omitting the last argument will sort the entire array. Note: this function is not tested.

Array2d

Include array2d.h to use. Defines two protected variables m_Width and m_Height (Again, by MFC convention, all member variables begin with m_) This template is derived from Set, not Array as you would think. The problem with the latter is that operator[] has to be defined returning different things; something C++ does not allow. The following functions are available:
Array2d (WORD h = 0, WORD w = 0)
Array2d (const Array2d& AnArray2d)
Array2d (const Array2dEl * AnArray2d, Array2dSizeType AHeight, Array2dSizeType AWidth)
Yup. These do exactly what you think.
Array2dEl * operator[] (Array2dSizeType index) const
This is done to allow using [][], as you get an array of the whole row. Neat huh? Too bad it's not my idea.
void Resize (WORD h, WORD w)
Yup. It does exactly what you think. All the data is preserved in the same shape, although if you shrink the array you will lose some.
Array2dSizeType Width (void) const
Array2dSizeType Height (void) const
These are also painfully obvious.

BitArray

To use include bitarray.h and link in -ladt. This is the class for the assembly programmer in you :) Enables you to work with as many bits as you like at a time. This is not a template and it is based on Array. It defines an internal protected variable m_nBits, containing the number of bits used. There maybe some left over, since everything has to be allocate with at least byte resolution. And don't try using brackets with this array. I have no idea how to let you assign to a bit that way. Brackets are delegated to Array - a feature, not a bug :) Here is the function list:
BitArray (ArraySizeType nElem = 0)
nElem here specifies the number of bits to allocate.
BitArray (const BitArray& AnArray)
Clone constructor...
BitArray (const BYTE * AnArray, ArraySizeType nElem)
Here nElem specifies the size of AnArray in bytes. A little inconsistent. Oh well...
const BOOL GetAt (ArraySizeType index) const
void SetAt (ArraySizeType index, BOOL Value)
void FlipAt (ArraySizeType index)
Use these to access individual bits. FlipAt will XOR the bit with 1.
WORD GetAt (ArraySizeType iStart, ArraySizeType iEnd) const
void SetAt (ArraySizeType iStart, ArraySizeType iEnd, WORD Value)
Use these to access chunks inside a bit array. I think this is really cool. You may still want to use bitfields for some things...
void Fill (BOOL Value)
Yes, it sets each bit to this value.
void Resize (ArraySizeType NewSize)
ArraySizeType Size (void) const
These work the same as in Set, except that the numbers are in bits.

CDate

Include cdate.h and link in -ladt to use. Named by MFC convention, this is a class to encapsulate date and time functions. This is not what you would use to make timers though. But it saves you some trouble using those incredibly messy localtime, time, and others. The internal protected variables are named the same as in struct tm. WeekdayEnum and MonthEnum are also defined internally although not used.
CDate (void)
CDate (const struct tm * ToBe)
CDate (const CDate& ToBe)
The null constructor intializes internals to zero, not to current time.
void Update (void)
Sets internal variables to current time and date.
void GetTime (WORD * hour, WORD * min, WORD * sec) const
void SetTime (WORD hour, WORD min, WORD sec)
void GetDate (WORD * year, WORD * month, WORD * day) const
void SetDate (WORD year, WORD month, WORD day)
WORD GetWeekday (void) const
WORD GetYearDay (void) const
Use these to manipulate the internal variables.
BOOL IsValid (void) const
Checks if the date you set up inside can ever happen. In other words, if your birthday doesn't check out here, you'll be a baby forever.
CDate& operator= (const CDate& ToBe);
BOOL operator== (const CDate& ToCompare);
BOOL operator> (const CDate& ToCompare);
BOOL operator< (const CDate& ToCompare);
BOOL operator>= (const CDate& ToCompare);
BOOL operator<= (const CDate& ToCompare);
CDate& operator+ (const CDate& ToAdd);
CDate& operator- (const CDate& ToSub);
Neat operators doing exactly what you think they'd do. The arithmetic operations will add up the years too!
void WriteTextStream (ostream& is);
This prints out and ascii date like this: Sun Feb 25 15:43:47 1996.
void ReadBinaryStream (istream& is);
void WriteBinaryStream (ostream& os);
These will write in a compact binary format using BitArray.
WORD StreamSize (void) const;
See Streamable.

Chain

To use include chain.h. This is a doubly-linked list template with as basic an interface as possible. All operations on data are link operations, like in all derived classes, so don't destroy your objects after inserting them here. This is not like Array. The destructor will delete all the objects pointed to by the links, so if you link the same object in several places, remove it manually. I chose this approach instead of the MFC-like negligence because I don't like to write the same code over and over and over... After all, you don't link the same objects in several places that often. Chain defines m_Head and m_Tail as private variables. You shouldn't use them. I am telling you this mostly to avoid name conflicts.

The internal design, if you are interested, works like this: when you want to insert a piece of data, Chain creates a "caddy" for it, a class template ChainLink, which will provide the links back and forward. ChainLink defines m_Data (pointer to your data) and links m_Next and m_Prev. Ok. That's enough. Lets look at member functions:

Chain (void)
Creates an empty chain.
ChainLink * MoveToHead (void) const
The 'MoveTo' convention is chosen mainly to avoid conflicts with LList. MoveTo also 'move's your pointer to the head of the list. Well, it was the best I could come up with. If you can do better, tell me. This function will return the head caddy pointer.
ChainLink * MoveToTail (void) const
This function will return the tail caddy pointer.
ChainLink * MoveToNext (const ChainLink * current) const
Will point passed caddy to the caddy after it.
ChainLink * MoveToPrev (const ChainLink * current) const
Will point passed caddy to the caddy before it.
void Disconnect (ChainLink * current)
Disconnects the current caddy from the chain. The data is not touched.
void ConnectAfter (ChainLink * current, ChainLink * newLink)
void ConnectBefore (ChainLink * current, ChainLink * newLink)
These names come out straight from my Pascal algorithm book. And since most of us have taken an algorithm course in college...
BOOL IsEmpty (void) const
TRUE if no caddies present.
~Chain (void)
Will disconnect all caddies and delete all the data present on them.

CSocket

To use include csocket.h and link in -ladt. Ever get tired of writing socket code? It is all the same, right? Here is a class to take care of socket problems. Encapsulates most of the information needed to run a socket. Can't live without it.

I defined a couple of macros, which I pray will help me port it to Winsock (synchronous of course). But you really shouldn't have to worry about these. They are

#define SOCKET		int
#define SOCKADDR_IN	struct sockaddr_in
#define HOSTENT		struct hostent
Anyway the socket class itself is mostly a base class. You can't really use it. Use CSocketClient and CSocketServer.
CSocket (void)
Allocates socket structures. Does not open the socket yet.
int GetSocketType (void)
Returns one of the following:
int GetStreamType (void)
Returns SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_SEQPACKET, or SOCK_RDM. See socket man page for more information.
int Read (char * buffer, int size)
Reads the specified number of bytes in buffer. Will hang there waiting until all the bytes are read, so you should add your own timeout routines. Returns the number of bytes read.
int Write (char * data, int size)
Will write the needed number of bytes. Returns number of bytes written.
void Read (int * buffer)
void Read (unsigned short int * buffer)
void Read (unsigned long int * buffer)
void Write (int data)
void Write (unsigned short int data)
void Write (unsigned long int data)
These do byte order conversions in addition to reading and writing.
int ReadLine (char * buffer, int size, char delim = '\n')
This one will read until specified delimiter is found. Comes in handy when dealing with most text-based servers.
void Close (void)
Closes the socket. Since there is nothing different about closing the socket in the client or the server, this is defined here in the base class.
~CSocket (void)
Destroys the socket structures. Does not close the socket.

CSocketClient

To use include csocket.h and link in -ladt. This is a base client class. It is derived from CSocket so all the IO functions are still there. Designed for simplicity. Feel free to derive your own classes.
CSocketClient (void)
Again, this does not establish the connection.
int Open (char * hostname, int port, int socktype = AF_INET, int strtype = SOCK_STREAM)
You have to use this function to establish a connection.
~CSocketClient (void)
Will not close the socket.

CSocketServer

To use include csocket.h and link in -ladt. This is a server template. You cannot create an instance of this, since UserServerProc is pure. Forking on accept is disabled by default for debugging. An internal variable m_IsForking determines this. Set it using SetForking call before running the server.
CSocketServer (void)
Does not open the connection.
int Open (int port, int socktype = AF_INET, int strtype = SOCK_STREAM)
Opens the connection.
void Run (void)
Enters an infinite loop waiting for calls. Will fork if m_IsForking is TRUE.
void UserServerProc (void) = 0
This is the function that you should override in your derived class, doing all the necessary processing for each call. Don't close the socket!
void EnableForking (void)
Sets m_IsForking to TRUE.
~CSocketServer (void)
Does not close the socket. Use Close().

CString

To use include cstring.h and link in -ladt. Derived from Streamable, so all appropriate functions are available. This was born out of frustration that UNIX does not have a string type. No, I don't like the GNU String. It's way too big and interface is a bit cumbersome. This one resemebles MFC CString a lot.

This class is not derived from Array as you would think. The overhead was quite unnecessary. CString defines its own m_Data, a char pointer. Allocation is dynamic; CString does not free allocated memory if you shorten the string. What if you want to increase it again? So two private variables are available for this purpose m_MemUsed and m_MemAllocated. Most functions depend on these and not on the null terminator, so you might as well have any binary data inside.

CString (void)
CString (char NewData)
CString (const char * NewData)
CString (int Size)
CString (const CString& NewData)
Various ways to create a string from scratch or from existing data.
WORD Size (void) const
Returns the current amount of memory used. This does not use strlen, so it is faster this way.
void Resize (WORD NewSize)
Reallocates storage to fit the new size. Will not shrink. Just grow.
CString& Left (WORD Count) const
Returns Count characters on the left.
CString& Middle (WORD Start, WORD Count) const
Extracts a substring.
CString& Right (WORD Count) const
Returns a CString with Count chars from the right.
void Append (WORD Num)
Appends a number (converted to ascii) to the string. This will be faster than printf ("%d").
void Append (const char * NewData, WORD DataSize)
Appends a character string of given size. Use this function to copy binary data into the string.
char GetAt (WORD idx) const
void SetAt (WORD idx, char Value)
Access individual elements using this. These are inlined for speed.
void InsertAt (WORD idx, char ToInsert)
void InsertAt (WORD idx, const char * ToInsert)
void InsertAt (WORD idx, const CString& ToInsert)
Various data insertions. The existing data will be shifted and the string resized.
void DeleteAt (WORD idx, WORD Count = 1)
Various data deleteions. The existing data will be shifted and the string resized.
int Index (const char ToFind) const
int Index (const char * ToFind) const
int Index (const CString& ToFind) const
Looks for stuff and returns an index.
BOOL Contains (const char ToFind) const
BOOL Contains (const char * ToFind) const
BOOL Contains (const CString& ToFind) const
Returns TRUE if what you are looking for is inside.
Array Split (const CString& delim = " \n\t") const
Perl-type split function. Returns an array of strings just like Perl's split. Read Perl man page. Use Perl. I love Perl.
CString& operator= (const CString& ToBe)
CString& operator= (const char ToBe)
CString& operator= (const char * ToBe)
BOOL operator== (const CString& ToCompare) const
BOOL operator< (const CString& ToCompare) const
BOOL operator> (const CString& ToCompare) const
char& operator[] (WORD idx)
const char& operator[] (WORD idx) const
operator const char * (void) const
operator char * (void)
CString& operator+ (const CString& ToAdd)
CString& operator+ (const char ToAdd)
CString& operator+ (const char * ToAdd)
All the wonderful operators that you can use with strings to make it into a normal data type.
~CString (void)
Will deallocate any allocated memory.

HashTable

To use include hash.h. This template implements string bucket hashing with attribute as a template. The keys are stored in a contiguous string table to save space. The following functions are protected for use in derived classes:
HashKeyType GetKey (char * Name);
Generates a hash key by adding together the first and last characters of Name.
BOOL IsEqual (char * Name, Bucket * ABucket)
Why didn't I implement this as an operator==? I have no idea.
The following functions are public:
HashTable (WORD NewTableSize = 50)
50 is a good number... The hash table is initialized as empty.
void Insert (char * Name, HashAttr * Attr)
Associates Attr with Name.
void Remove (char * Name)
Removes everything associated with Name.
HashAttr * Lookup (char * Name)
Returns the attribute record associated with Name
void Clear (void)
Kills all the poor and defenseless entries in the table creating a disguisting electronic bitshed.
~HashTable (void)
Yes, this will do the same as Clear but it will clean up too.

LCList

To use include lclist.h. This is an add-on to LList to make it into a circular linked list. I just overloaded movement operators (Next, Prev) so that they wrap around. Everything else works fine just the way it is. Not much to say here. Go look at LList.

LList

To use include llist.h. This is a doubly-linked list template based on Chain. I have never had a need for a singly-linked list, so I didn't implement that one. The concept here is again taken from my Pascal algorithm class in college: we have "windows" into the list, which can be moved. This is implemented by using an array of Chain caddy pointers called m_Windows. Since the programmer should not even know about Chain while using LList, these are only referenced by indeces. Window zero is the default. Its position is undefined after all operations. Use other windows (1-9) if you want to be sure where they are. You can "look" through a window, insert and remove elements, etc. I have added several convenience functions, like Size(), which are not present in the ADT specs (The size is stored in an internal variable m_Size. The following member functions are available:
LList (void)
Constructs an empty list.
void Next (ListWin wid = 0)
Moves the given window to the next element. Will drop off the end.
void Prev (ListWin wid = 0);
Moves the given window to the previous element. Will drop off the end.
void Head (ListWin wid = 0);
Moves to head.
void Tail (ListWin wid = 0);
Moves to tail.
void Skip (int count, ListWin wid = 0)
Skips over count elements with wid.
BOOL OnList (ListWin wid = 0) const
Returns TRUE if wid is positioned on a valid element inside the list. Note: this function does not look for the element in the chain. It just checks if it is NULL.
void InsertBefore (LListEl * data, ListWin wid = 0)
Inserts the given data before wid. This is a link operation. Don't delete data!
void InsertAfter (LListEl * data, ListWin wid = 0)
Inserts the given data after wid. This is a link operation. Don't delete data!
LListEl * Remove (ListWin wid = 0)
Returns the element seen through wid and removes it. The position of the window is undefined after this (currently it is moved to the head)
void Delete (ListWin wid = 0)
Removes the element at wid and deletes its data. The position of the window is undefined after this (currently it is moved to the head)
LListEl * LookAt (ListWin wid = 0) const
Returns the pointer to the data of the element pointed to by wid.
LListEl * operator[] (ListSizeType index)
A cheat :) You are not supposed to do this, but do it anyway!
ListSizeType Size (void) const
Returns the number of elements in the list.
~LList (void)
Removes every element and deletes all data on those elements.

Matrix

To use include matrix.h. Question: what's the difference between a matrix and a 2d array? Answer: matrix is a mathematical entity with corresponding operations defined. Use with cardinal or floating point entries only. Well, you could use others but you'll have to define a bunch of operators for your type. Member functions:
Matrix (WORD h = 0, WORD w = 0)
Matrix (const Matrix& AMatrix)
Matrix (const MatrixEl * AMatrix, MatrixSizeType AHeight, MatrixSizeType AWidth)
Various ways of creating a Matrix with existing data or from scratch.
Matrix& operator+ (const Matrix& toAdd) const
Performs matrix addition. Dimensions must be the same.
Matrix& operator- (const Matrix& toSub) const
Performs matrix subtraction. Dimensions must be the same.
Matrix& operator* (MatrixEl scalar) const
Performs scalar multiplication.
Matrix& operator* (const Matrix& toMul) const
Performs matrix multiplication. Width of first operand must match height of second.
void Transpose (void)
Makes columns rows and rows columns.
void RowReduce (void)
Is not implemented.
MatrixEl Determinant (void)
Uses row reduction and multiplies the entries on the diagonal. Must have a square matrix. Does not work until row reduction is implemented. I have not needed this yet, so it is not there.

Queue

To use include queue.h. Another fine example of a Pascal-like ADT. Based on Chain. Member functions:
void Append (QueueEl * element)
Appends the element on the end.
QueueEl * Serve (void)
Removes one element from the front.
QueueEl * Front (void)
Looks at the element on the front without removing it.

Set

To use include set.h. This is a generic container template. Not very useful by itself, it serves mainly as a base for other containers. This class is Streamable. It defines an array of elements, stored in private variable m_Data with size stored in m_Size. No orderly access is provided, this is more like a bag of stuff that you can rummage through without being able to say "I want item three". This class needs to be more developed. Member functions:
Set (SetSizeType nElem = 0);
Defines a set of size nElem. The size later can be changed using Resize().
Set (const Set& ASet)
Copy constructor.
Set (const SetEl * ASet, SetSizeType nElem)
Set from an array. The above three constructors should be present in every class derived from Set. The are in all mine.
Set& operator= (const Set& toBe)
Set& operator= (const SetEl * toBe)
See the constructors above.
BOOL operator== (const Set& toCompare) const
This matches two sets. Right now it is a cheat, using array comparison, but in the future it will be a true blind match operation not depending on order.
operator const SetEl * () const
Obvious...
void Resize (SetSizeType NewSize)
Changes the size of the set. If shrinking, some items may be dropped. If expanding all the items will be kept.
void Fill (SetEl value)
Sets every element to value.
SetSizeType Size (void) const
Returns the number of elements in the set.
SetSizeType Find (SetEl match) const
Find a matching element and returns a positive value if found. DON'T assume it returns an index. It does now, but I'll change that.
~Set (void)
Destroys all elements in the set.

Stack

To use include stack.h. Another fine example of a Pascal-like ADT. Based on Chain. Member functions:
void Push (StackEl * element)
Inserts the element on the top.
StackEl * Pop (void)
Removes an element from the top.
StackEl * Top (void)
Looks at the top element without removing it.

Streamable

To use include streamab.h. This is a base class for anything that can be saved or loaded, read or written. It provides overloads of << and >> and several other useful functions like Read*StringStream, which allow saving to strings. The good thing about this is that you only have to overload Read*Stream and/or Write*Stream, whichever one you need. Overload WriteBinaryStream to write illegible data to a data file. Overload WriteTextStream to produce human-readable output. If you have a *BinaryStream overload, define a StreamSize function to estimate the size of the data to be read or written. Obviously I have no idea what the size is going to be or what to write in Streamable, so all functions are defined to print out a warning if called. The names are long, but they are the only ones I could come up with that would convey their function. Member functions:
void Load (char * filename)
Opens filename for reading and calls ReadBinaryStream.
void Save (char * filename)
Opens filename for writing and calls WriteBinaryStream.
WORD StreamSize (void) const
Returns an estimate of the size of the binary data.
void ReadBinaryStream (istream& is)
Reads data from is.
void ReadTextStream (istream& is)
Reads human-readable data from is.
void WriteBinaryStream (ostream& os)
Writes data to os.
void WriteTextStream (ostream& os)
Writes human-readable data to os.
void ReadBinaryStringStream (const char * StreamBuf, WORD StrSize)
Reads binary data from a string.
void ReadTextStringStream (const char * StreamBuf, WORD StrSize)
Reads human-readable data from a string.
void WriteBinaryStringStream (char * StreamBuf, WORD StrSize)
Writes binary data to a string.
void WriteTextStringStream (char * StreamBuf, WORD StrSize)
Writes human-readable data to a string.

Vector

To use include vector.h. A Vector is a kind of Matrix. See Matrix for argument on why this is not an array. Member functions:
Vector (VectorSizeType s = 0)
Creates a vector of given size.
Vector& operator= (const Vector& toBe)
Copy.
Vector& operator= (const Matrix& toBe)
Copy
VectorEl& operator[] (VectorSizeType index)
Returns the element at index.
VectorEl operator* (const Vector& toDot)
Does a dot product on given two vectors.
Vector& Cross (const Vector& toCross)
Does a cross product on given two vectors. Vectors should be of size 3.
VectorEl Length (void) const
Returns the number of elements (components?).
void Resize (VectorSizeType s)
Changes the number of elements.

Other tools

The library contains a collection of helper functions outside classes. Some convenient data types are defined and some portability macros are defined too.

Endian issues

Too bad the C library does not provide an easy way to set endianness. Here are some functions to remedy that defined in cendian.h: These simply swap bytes depending on the state of the __BYTE_ORDER macro. On Linux this macro is defined by the system include files, so you may have to define it manually to be either __BIG_ENDIAN or __LITTLE_ENDIAN. On Linux these are defined as 4321 and 1234 respectively, but you don't have to care as long as they are different.

Miscellaneous common functions

There are a few things that you use all the time. But the C library often does not define them. Here are some examples, all defined in mdefs.h, which can also be included in C files, not just C++. The only difference would be that all templates, like min will be replaced by macros. How can one live without these? And most C compilers don't have the bool type yet... The eternal problem: what to return from a function as status. Should it be a zero? Should it be positive? Use these macros! Tired of typing 'unsigned long int'? Use WORD! The point here is to make BYTE 8 bits and WORD 32 bits. So on whichever machine you are running, make sure this is true.
MinVal min (MinVal a, MinVal b)
MaxVal max (MaxVal a, MaxVal b)
All these are templates if in C++, macros if in C. Use abundantly.
DiffVal diff (DiffVal a, DiffVal b)
Why isn't there an easier way to find a difference?
RandLimit randnum (RandLimit range)
This is supposed to be better than C's random number functions. I got the algorithm out of a book that said it was one of the best. It could be wrong.
int sign (Num x)
This function is often missed in C libraries.
BOOL member (ArrayEl el, ArrayEl * arr, size_t size)
Want to know if 'a' is present in the string the user just typed in?

Streamable helper functions

You are supposed to use these in Streamable-based classes. These functions take care of byte order for you for one thing.