8.86. File tom/unique-strings

class tom.UniqueString

inherits

State supers: String

variables

static MutableSet strings;

The Container of all unique strings. The container mechanism will ensure only those strings are kept that are still needed.

methods


void
  load Array arguments;

Initialize the strings Container.


instance (id)
  with String s;

Return the UniqueString containing the same information as the String s. This is the only method to be used to create unique strings.


protected instance (id)
  awake instance (id) us
  equal selector cmp;

Find the string us in the strings, comparing them using the selector cmp. If the string is found, the old string is returned. Otherwise, us is added to the strings and it is returned.

instance tom.UniqueString

variables

int hash;

The cached hash value of this string.

methods


boolean
  equal String other;

Tell the other to compare itself to this UniqueString.


boolean
  equalUniqueString UniqueString other;

Return TRUE. This is simple pointer comparison.


int
  compare id other;

Override compare, to return fast upon equality.

class tom.UniqueByteString

inherits

State supers: UniqueString, ByteString

instance tom.UniqueByteString

methods


boolean
  equal String other;

This definition is only here because we can not direct the implementation of this selector to the right class.


boolean
  equalUniqueString UniqueString other;

The same is true for this one.


int
  hash;

When called for the first time, hash the string, and remember the value. Every next time, return the cached value. Obviously, this loses for strings with a zero hash value (which keep being hashed).


id
  awakeAfterUsingCoder Decoder coder;

Iff a unique string like the receiving one already exists, return the already existing one. Otherwise, add the receiving string to the known unique strings.

class tom.UniqueCharString

inherits

State supers: UniqueString, CharString

instance tom.UniqueCharString

methods


boolean
  equal String other;

Redefinition since we can not redirect to the right (UniqueString) super.


boolean
  equalUniqueString UniqueString other;

Redefinition since we can not redirect to the right (UniqueString) super.


int
  hash;

Cached hashing, just like UniqueByteString.


id
  awakeAfterUsingCoder Decoder coder;

Iff a unique string like the receiving one already exists, return the already existing one. Otherwise, add the receiving string to the known unique strings.