|
ESC/Java2 © 2003,2004,2005 David Cok and Joseph Kiniry © 2005 UCD Dublin © 2003,2004 Radboud University Nijmegen © 1999,2000 Compaq Computer Corporation © 1997,1998,1999 Digital Equipment Corporation All Rights Reserved |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavafe.ast.Identifier
An Identifier
is a symbol, that is, a sequence of
characters. Identifier
s are interned: for any given
sequence of characters, we create exactly one instance of
Identifier
to represent it (we say that the sequence
of characters is associated with this
Identifier
instance). This allows us to use object
equality (that is, ==
) to check symbol equality.
This class is thread-safe: multiple threads can enter its any of its methods (static or non-static) simultaneously.
Field Summary | |
private static Identifier[][] |
chains
Table containing every instance of Identifier
created. |
private char[] |
chars
Sequence of characters represented by this Identifier (never null ). |
private java.lang.String |
equiv
Memoization of String.valueOf(chars, 0,
chars.length) ; may be null . |
(package private) static int |
HC
Constant used for hashing. |
private static int |
INITIAL_CHAIN_SIZE
Initial size of chains inside the table. |
private static int |
TABLE_SIZE
Size of intern table. |
(package private) int |
tokenType
This field defaults to TagConstants.IDENT , but
is set to other values by the scanner to indicate keywords. |
Constructor Summary | |
private |
Identifier(char[] text,
int textlen,
int hashcode)
|
Method Summary | |
static void |
check()
Return true if all invariants are satisfied. |
boolean |
equals(java.lang.Object o)
|
(package private) static int |
hash(char[] text,
int textlen)
|
(package private) static int |
hash(java.lang.String s)
|
int |
hashCode()
|
(package private) static Identifier |
intern(char[] text,
int textlen,
int hashcode)
Intern a sequence of characters with a pre-computed hashcode. |
static Identifier |
intern(java.lang.String s)
Returns the Identifier associated with
s. |
static void |
main(java.lang.String[] argv)
|
private static Identifier |
slowFind(java.lang.String s)
Used by check ; checks for duplicates. |
java.lang.String |
toString()
Return a string containing the symbol associated with this . |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
private static final int TABLE_SIZE
private static final Identifier[][] chains
Identifier
created. If a symbol s has been interned, its
associated Identifier
is found by hashing it to
integer h such that 0 <= h <= TABLE_SIZE,
looking up v = chains[h], which is a an array of arrays
of Identifier
s, then searching v for the
Identifier
associated with s. If no such
element exists, then s hasn't been interned yet.
This table is only extended, old parts are never updated.
Thus, reading the table can occur without any locks being held.
Extension of the table is protected by the mutex associated with
the table itself (that is, the object pointed to by
chains
.
private static final int INITIAL_CHAIN_SIZE
private char[] chars
null
).
private java.lang.String equiv
String.valueOf(chars, 0,
chars.length)
; may be null
. This variable may
be written exactly once.
static final int HC
idn
is to sum
HC
^(n-(i+1))*idn[
i]
.
Note that this is the same hash function used by Java 1.1 for
hashing String
objects.
int tokenType
TagConstants.IDENT
, but
is set to other values by the scanner to indicate keywords.
Constructor Detail |
private Identifier(char[] text, int textlen, int hashcode)
Method Detail |
public static Identifier intern(java.lang.String s)
Identifier
associated with
s.
static Identifier intern(char[] text, int textlen, int hashcode)
hashcode = Identifier.hash(text, textlen)
Ensures: returns the Identifier
instance
associated with the symbol consisting of the first
textlen
characters of text
.
static int hash(java.lang.String s)
static int hash(char[] text, int textlen)
public java.lang.String toString()
this
.
public int hashCode()
public boolean equals(java.lang.Object o)
public static void check()
private static Identifier slowFind(java.lang.String s)
check
; checks for duplicates.
public static void main(java.lang.String[] argv)
|
ESC/Java2 © 2003,2004,2005 David Cok and Joseph Kiniry © 2005 UCD Dublin © 2003,2004 Radboud University Nijmegen © 1999,2000 Compaq Computer Corporation © 1997,1998,1999 Digital Equipment Corporation All Rights Reserved |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |