diff options
author | Todd Lipcon <todd@apache.org> | 2012-05-17 22:30:46 +0000 |
---|---|---|
committer | Todd Lipcon <todd@apache.org> | 2012-05-17 22:30:46 +0000 |
commit | 5258d6bf3fb8090739cf96f5089f96cee87393c4 (patch) | |
tree | e98a6662cad92c42fee5f5abbeea7ea93b5b0915 /hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightHashSet.java | |
parent | 15ddb6634f8bdab37ce43f99f8338d84422c7232 (diff) |
HDFS-3391. Fix InvalidateBlocks to compare blocks including their generation stamps. Contributed by Todd Lipcon.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1339897 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightHashSet.java')
-rw-r--r-- | hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightHashSet.java | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightHashSet.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightHashSet.java index 13ca8b45c5..90471bba58 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightHashSet.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightHashSet.java @@ -173,31 +173,42 @@ public class LightWeightHashSet<T> implements Collection<T> { * @return true if element present, false otherwise. */ @SuppressWarnings("unchecked") + @Override public boolean contains(final Object key) { + return getElement((T)key) != null; + } + + /** + * Return the element in this set which is equal to + * the given key, if such an element exists. + * Otherwise returns null. + */ + public T getElement(final T key) { // validate key if (key == null) { throw new IllegalArgumentException("Null element is not supported."); } // find element - final int hashCode = ((T)key).hashCode(); + final int hashCode = key.hashCode(); final int index = getIndex(hashCode); - return containsElem(index, (T) key, hashCode); + return getContainedElem(index, key, hashCode); } /** - * Check if the set contains given element at given index. + * Check if the set contains given element at given index. If it + * does, return that element. * - * @return true if element present, false otherwise. + * @return the element, or null, if no element matches */ - protected boolean containsElem(int index, final T key, int hashCode) { + protected T getContainedElem(int index, final T key, int hashCode) { for (LinkedElement<T> e = entries[index]; e != null; e = e.next) { // element found if (hashCode == e.hashCode && e.element.equals(key)) { - return true; + return e.element; } } // element not found - return false; + return null; } /** @@ -240,7 +251,7 @@ public class LightWeightHashSet<T> implements Collection<T> { final int hashCode = element.hashCode(); final int index = getIndex(hashCode); // return false if already present - if (containsElem(index, element, hashCode)) { + if (getContainedElem(index, element, hashCode) != null) { return false; } |