UniqueStringID Class Reference

This class is used to store a unique value for a particular integer/string combination.

Detailed Description

The string itself is not stored, nor is the integer: all operations are unidirectional, so UniqueStringID's cannot be converted BACK into a string and integer. Instantiating this class with the same string and ID; should always yield an equivalent UniqueStringID, even across editor-sessions. UniqueStringID's can be quickly compared with other UniqueStringIDs for equality.(operator==) E.g. for large Dictionaries, that use large strings as the key, converting the string to a UniqieID, and using THAT for they Dictionary key can lead to faster lookups, a smaller memory footprint, and shorter serialization time.
But note: conversion from string to UniqueID is usually (depending on the size of the string) a fairly costly operation, so BUILDING the dictionary would be slower. Even for lookups, the time to compute the UniqueID from the input string, cannot be ignored and will only benefit dictionaries that are over a certain size.

Public Member Functions

 UniqueStringID ()
 This constructor does noting, all internal values will be initialized with zeros. Only use this if intending to fill the instance will ReadFromStream.
 
 UniqueStringID (int IDnumber, string s)
 Will generate UniqueStringID stats for this string, and use the provided ID value.
 
 UniqueStringID (object o, string s)
 Will generate UniqueStringID stats for this string, and use the object's GetHashCode() for the ID value.
 
 UniqueStringID (string s)
 Default constructor for a given string. Will generate UniqueStringID stats for this string, and assume an ID value of zero.
 
override bool Equals (object obj)
 Checks if the provided object is a UniqueStringID, and invoked operator== if so, and returns false if not.
 
bool Equals (UniqueStringID obj)
 Checks if the provided object is not null, and invokes operator== if so, and returns false if not.
 
override int GetHashCode ()
 A specific section of the stats data is returned as the HashCode.
Two objects that are equal return hash codes that are equal. However, the reverse is not true: equal hash codes do not imply object equality, because different (unequal) objects can have identical hash codes.
 
int ReadFromStream (System.IO.BinaryReader readStream)
 Implementation of IStreamable. Reads the data contained in the provided BinaryReader into the stats contained in this instance.
 
void SendToStream (System.IO.BinaryWriter stream)
 Implementation of IStreamable. Writes the current stats contained in this instance to the provided BinaryWriter.
 
void SetupStringStats (int ID, string str)
 Setup function performs the computation to generate the stats from the provided input. Provides the main functionality of this class.
 
override string ToString ()
 Displays the stats stored in this instance.
 

Static Public Member Functions

static bool operator!= (UniqueStringID x, UniqueStringID y)
 Invokes the operator== , the result is negated and returned.
 
static bool operator== (UniqueStringID x, UniqueStringID y)
 Checks if the two provided UniqueStringID objects have the same stats. Returns true if so, false if not. Also returns true if BOTH objects are null.
 
+ Inheritance diagram for UniqueStringID:
+ Collaboration diagram for UniqueStringID: