use of com.fasterxml.jackson.core.sym.CharsToNameCanonicalizer in project fastjson by alibaba.
the class SymbolTableTest method test_symbol.
public void test_symbol() throws Exception {
char[][] symbols_char = new char[symbols.length][];
for (int i = 0; i < symbols.length; ++i) {
symbols_char[i] = symbols[i].toCharArray();
}
{
CharsToNameCanonicalizer table = CharsToNameCanonicalizer.createRoot();
for (int i = 0; i < symbols.length; ++i) {
String symbol = symbols[i];
table.findSymbol(symbol.toCharArray(), 0, symbol.length(), symbol.hashCode());
}
}
SymbolTable table = new SymbolTable(512);
for (int i = 0; i < symbols.length; ++i) {
String symbol = symbols[i];
char[] charArray = symbol.toCharArray();
table.addSymbol(charArray, 0, charArray.length);
//System.out.println((table.hash(symbol) & table.getIndexMask()) + "\t\t:" + symbol + "\t\t" + table.hash(symbol));
}
String symbol = "name";
table.addSymbol(symbol.toCharArray(), 0, symbol.length());
table.addSymbol(symbol.toCharArray(), 0, symbol.length());
Assert.assertTrue(symbol == table.addSymbol("name".toCharArray(), 0, 4));
Assert.assertTrue(symbol == table.addSymbol(" name".toCharArray(), 1, 4));
Assert.assertTrue(symbol == table.addSymbol(" name ".toCharArray(), 1, 4));
Assert.assertTrue(symbol != table.addSymbol(" namf ".toCharArray(), 1, 4));
}
Aggregations