Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | package com.google.devtools.build.lib.util; |
| 15 | |
| 16 | /** |
| 17 | * An object that provides bidirectional String <-> unique integer mapping. |
| 18 | */ |
| 19 | public interface StringIndexer { |
| 20 | |
| 21 | /** |
| 22 | * Removes all mappings. |
| 23 | */ |
| 24 | public void clear(); |
| 25 | |
| 26 | /** |
| 27 | * @return some measure of the size of the index. |
| 28 | */ |
| 29 | public int size(); |
| 30 | |
| 31 | /** |
| 32 | * Creates new mapping for the given string if necessary and returns |
| 33 | * string index. Also, as a side effect, zero or more additional mappings |
| 34 | * may be created for various prefixes of the given string. |
| 35 | * |
| 36 | * @return a unique index. |
| 37 | */ |
| 38 | public int getOrCreateIndex(String s); |
| 39 | |
| 40 | /** |
| 41 | * @return a unique index for the given string or -1 if string |
| 42 | * was not added. |
| 43 | */ |
| 44 | public int getIndex(String s); |
| 45 | |
| 46 | /** |
| 47 | * Creates mapping for the given string if necessary. |
| 48 | * Also, as a side effect, zero or more additional mappings may be |
| 49 | * created for various prefixes of the given string. |
| 50 | * |
| 51 | * @return true if new mapping was created, false if mapping already existed. |
| 52 | */ |
| 53 | public boolean addString(String s); |
| 54 | |
| 55 | /** |
| 56 | * @return string associated with the given index or null if |
| 57 | * mapping does not exist. |
| 58 | */ |
| 59 | public String getStringForIndex(int i); |
| 60 | |
| 61 | } |