Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public V get(String key, HashNode<String, V>[] arr) {
- return getHelper(key, arr, 0, arr.length - 1);
- }
- /**
- * Gets the helper.
- *
- * @param key the key
- * @param arr the arr
- * @param left the left
- * @param right the right
- * @return the helper
- */
- private V getHelper(String key, HashNode<String, V>[] arr, int left,
- int right) {
- if (left > right)
- return null;
- int middle = (left + right) / 2;
- if (arr[middle].getKey().equals(key))
- return arr[middle].getValue();
- else if (arr[middle].getKey().compareTo(key) > 0)
- return getHelper(key, arr, left, middle - 1);
- else
- return getHelper(key, arr, middle + 1, right);
- }
- /**
- * Contains.
- *
- * @param key the key
- * @param arr the arr
- * @return true, if successful
- */
- public boolean contains(String key, HashNode<String, V>[] arr) {
- return containsHelper(key, arr, 0, arr.length - 1);
- }
- /**
- * Contains helper.
- *
- * @param key the key
- * @param arr the arr
- * @param left the left
- * @param right the right
- * @return true, if successful
- */
- private boolean containsHelper(String key, HashNode<String, V>[] arr, int left,
- int right) {
- if (left > right)
- return false;
- int middle = (left + right) / 2;
- if (arr[middle].getKey().equals(key))
- return true;
- else if (arr[middle].getKey().compareTo(key) > 0)
- return containsHelper(key, arr, left, middle - 1);
- else
- return containsHelper(key, arr, middle + 1, right);
- }
Add Comment
Please, Sign In to add comment