| 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 | // Copyright (c) 2018 Saxonica Limited. |
| 3 | // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. |
| 4 | // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. |
| 6 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 7 | |
| 8 | package net.sf.saxon.z; |
| 9 | |
| 10 | /** |
| 11 | * Interface defining a map from integers to integers |
| 12 | */ |
| 13 | public interface IntToIntMap { |
| 14 | /** |
| 15 | * Set the value to be returned to indicate an unused entry |
| 16 | * |
| 17 | * @param defaultValue the value to be returned by {@link #get(int)} if no entry |
| 18 | * exists for the supplied key |
| 19 | */ |
| 20 | void setDefaultValue(int defaultValue); |
| 21 | |
| 22 | /** |
| 23 | * Get the default value used to indicate an unused entry |
| 24 | * |
| 25 | * @return the value to be returned by {@link #get(int)} if no entry |
| 26 | * exists for the supplied key |
| 27 | */ |
| 28 | |
| 29 | int getDefaultValue(); |
| 30 | |
| 31 | /** |
| 32 | * Clear the map. |
| 33 | */ |
| 34 | void clear(); |
| 35 | |
| 36 | /** |
| 37 | * Finds a key in the map. |
| 38 | * |
| 39 | * @param key Key |
| 40 | * @return true if the key is mapped |
| 41 | */ |
| 42 | boolean find(int key); |
| 43 | |
| 44 | /** |
| 45 | * Gets the value for this key. |
| 46 | * |
| 47 | * @param key Key |
| 48 | * @return the value, or the default value if not found. |
| 49 | */ |
| 50 | int get(int key); |
| 51 | |
| 52 | /** |
| 53 | * Gets the size of the map. |
| 54 | * |
| 55 | * @return the size |
| 56 | */ |
| 57 | int size(); |
| 58 | |
| 59 | /** |
| 60 | * Removes a key from the map. |
| 61 | * |
| 62 | * @param key Key to remove |
| 63 | * @return true if the value was removed |
| 64 | */ |
| 65 | boolean remove(int key); |
| 66 | |
| 67 | /** |
| 68 | * Adds a key-value pair to the map. |
| 69 | * |
| 70 | * @param key Key |
| 71 | * @param value Value |
| 72 | */ |
| 73 | void put(int key, int value); |
| 74 | |
| 75 | /** |
| 76 | * Get an iterator over the integer key values held in the hash map |
| 77 | * |
| 78 | * @return an iterator whose next() call returns the key values (in arbitrary order) |
| 79 | */ |
| 80 | |
| 81 | /*@NotNull*/ IntIterator keyIterator(); |
| 82 | } |