MCPcopy
hub / github.com/kevin-wayne/algs4 / rank

Method rank

src/main/java/edu/princeton/cs/algs4/SuffixArray.java:170–180  ·  view source on GitHub ↗

Returns the number of suffixes strictly less than the query string. We note that rank(select(i)) equals i for each i between 0 and n -1. @param query the query string @return the number of suffixes strictly less than query

(String query)

Source from the content-addressed store, hash-verified

168 * @return the number of suffixes strictly less than {@code query}
169 */
170 public int rank(String query) {
171 int lo = 0, hi = suffixes.length - 1;
172 while (lo <= hi) {
173 int mid = lo + (hi - lo) / 2;
174 int cmp = compare(query, suffixes[mid]);
175 if (cmp < 0) hi = mid - 1;
176 else if (cmp > 0) lo = mid + 1;
177 else return mid;
178 }
179 return lo;
180 }
181
182 // compare query string to suffix
183 private static int compare(String query, Suffix suffix) {

Callers 3

mainMethod · 0.95
mainMethod · 0.95
mainMethod · 0.95

Calls 1

compareMethod · 0.95

Tested by

no test coverage detected