private static BinaryNameMatcher _construct(List<String> symbols, SimpleNameMatcher base) { int sz = _findSize(symbols.size()); String[] lookup = symbols.toArray(new String[symbols.size()]); BinaryNameMatcher matcher = new BinaryNameMatcher(base, lookup, sz); for (String name : symbols) { matcher.addName(name); } return matcher; }
public int addName(String name) { byte[] ch = name.getBytes(StandardCharsets.UTF_8); int len = ch.length; if (len <= 12) { if (len <= 4) { return addName(name, _decodeLast(ch, 0, len)); } int q1 = _decodeFull(ch, 0); if (len <= 8) { return addName(name, q1, _decodeLast(ch, 4, len-4)); } return addName(name, q1, _decodeFull(ch, 4), _decodeLast(ch, 8, len-8)); } int[] quads = _quads(name); return addName(name, quads, quads.length); }
private int addName(String name, int[] q, int qlen) { switch (qlen) { case 1: return addName(name, q[0]); case 2: return addName(name, q[0], q[1]); case 3: return addName(name, q[0], q[1], q[2]); } final int index = _count; final int hash = calcHash(q, qlen); int offset = _findOffsetForAdd(hash); _hashArea[offset] = hash; int longStart = _appendLongName(q, qlen); _hashArea[offset+1] = longStart; _hashArea[offset+3] = _lengthAndIndex(qlen); // increases _count return index; }