簡體   English   中英

ConcurrentSkipListMap和多列比較器

[英]ConcurrentSkipListMap and multi-column comparator

我有以下課程KeyObj

public class KeyObject {
    private byte[] P1;
    private byte[] P2;
    private byte[] P3;
}

我想將此類的對象放入ConcurrentSkipListMap我對如何編寫比較器感到困惑,以便可以進行范圍查詢。 也就是說,如果給定P1 ,那么它將返回我p2 and p3 像下面這樣

KeyObject fromKey = new KeyObject(K1.P1, P2_MIN_VALUE, P3_MIN_VALUE);
KeyObject toKey = new KeyObject(K2.P1, P2_MAX_VALUE, P3_MAX_VALUE);
ConcurrentNavigableMap<KeyObject, Object> subview = table.submap(fromkey, toKey);
for (ConcurrentSkipListMap.Entry<KeyObject, Object> entry : subView.entrySet()) {
...
}

要么

KeyObject fromKey = new KeyObject(K1.P1, K1.P2, P3_MIN_VALUE);
KeyObject toKey = new KeyObject(K2.P2, K2.P2, P3_MAX_VALUE);
ConcurrentNavigableMap<KeyObject, Object> subview = table.submap(fromkey, toKey);
for (ConcurrentSkipListMap.Entry<KeyObject, Object> entry : subView.entrySet()) {
...
}

使用可比較或比較器接口,並定義方法以希望它們表現的方式進行比較或比較。

阿傑

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM