forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7f9ccb
commit b06cba6
Showing
4 changed files
with
117 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...main/java/org/apache/pulsar/common/util/collections/ConcurrentTripleLong2LongHashMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.apache.pulsar.common.util.collections; | ||
|
||
import java.util.HashMap; | ||
|
||
public class ConcurrentTripleLong2LongHashMap { | ||
public class TripleLong{ | ||
public long first; | ||
public long second; | ||
public long third; | ||
@Override | ||
public int hashCode() { | ||
return Long.hashCode(first) ^ Long.hashCode(second) ^ Long.hashCode(third); | ||
} | ||
@Override | ||
public boolean equals(Object obj) { | ||
if(obj instanceof TripleLong){ | ||
TripleLong other = (TripleLong) obj; | ||
return first == other.first && second == other.second && third == other.third; | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
private HashMap<TripleLong, Long> map; | ||
public ConcurrentTripleLong2LongHashMap(){ | ||
// TODO: use hashmap for now | ||
map = new HashMap<>(); | ||
} | ||
public void put(long first, long second, long third, long value){ | ||
TripleLong key = new TripleLong(); | ||
key.first = first; | ||
key.second = second; | ||
key.third = third; | ||
map.put(key, value); | ||
} | ||
public long get(long first, long second, long third){ | ||
TripleLong key = new TripleLong(); | ||
key.first = first; | ||
key.second = second; | ||
key.third = third; | ||
return map.get(key); | ||
} | ||
public long remove(long first, long second, long third){ | ||
TripleLong key = new TripleLong(); | ||
key.first = first; | ||
key.second = second; | ||
key.third = third; | ||
return map.remove(key); | ||
} | ||
public boolean containsKey(long first, long second, long third){ | ||
TripleLong key = new TripleLong(); | ||
key.first = first; | ||
key.second = second; | ||
key.third = third; | ||
return map.containsKey(key); | ||
} | ||
public void clear(){ | ||
map.clear(); | ||
} | ||
public long size(){ | ||
return map.size(); | ||
} | ||
public boolean isEmpty() { | ||
return map.isEmpty(); | ||
} | ||
|
||
public interface TripleLongConsumer { | ||
void call(long first, long second, long third, long value); | ||
} | ||
public void forEach(TripleLongConsumer consumer){ | ||
for(TripleLong key : map.keySet()){ | ||
consumer.call(key.first, key.second, key.third, map.get(key)); | ||
} | ||
} | ||
|
||
} |