本文整理汇总了Java中com.google.common.primitives.UnsignedBytes.lexicographicalComparator方法的典型用法代码示例。如果您正苦于以下问题:Java UnsignedBytes.lexicographicalComparator方法的具体用法?Java UnsignedBytes.lexicographicalComparator怎么用?Java UnsignedBytes.lexicographicalComparator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.primitives.UnsignedBytes
的用法示例。
在下文中一共展示了UnsignedBytes.lexicographicalComparator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openClosedBackwardTestWithGuava
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Test
public void openClosedBackwardTestWithGuava() {
final Comparator<byte[]> guava = UnsignedBytes.lexicographicalComparator();
final Comparator<ByteBuffer> comparator = (bb1, bb2) -> {
final byte[] array1 = new byte[bb1.remaining()];
final byte[] array2 = new byte[bb2.remaining()];
bb1.mark();
bb2.mark();
bb1.get(array1);
bb2.get(array2);
bb1.reset();
bb2.reset();
return guava.compare(array1, array2);
};
verify(openClosedBackward(bb(7), bb(2)), comparator, 6, 4, 2);
verify(openClosedBackward(bb(8), bb(4)), comparator, 6, 4);
}
示例2: createIndexes
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
protected void createIndexes(DB database)
{
//HEIGHT INDEX
Tuple2Comparator<Integer, byte[]> comparator = new Fun.Tuple2Comparator<Integer, byte[]>(Fun.COMPARATOR, UnsignedBytes.lexicographicalComparator());
NavigableSet<Tuple2<Integer, byte[]>> heightIndex = database.createTreeSet("blocks_index_height")
.comparator(comparator)
.makeOrGet();
NavigableSet<Tuple2<Integer, byte[]>> descendingHeightIndex = database.createTreeSet("blocks_index_height_descending")
.comparator(new ReverseComparator(comparator))
.makeOrGet();
createIndex(HEIGHT_INDEX, heightIndex, descendingHeightIndex, new Fun.Function2<Integer, byte[], Block>() {
@Override
public Integer run(byte[] key, Block value) {
return value.getHeight();
}
});
}
示例3: createIndexes
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void createIndexes(DB database)
{
//TIMESTAMP INDEX
Tuple2Comparator<Long, byte[]> comparator = new Fun.Tuple2Comparator<Long, byte[]>(Fun.COMPARATOR, UnsignedBytes.lexicographicalComparator());
NavigableSet<Tuple2<Integer, byte[]>> heightIndex = database.createTreeSet("transactions_index_timestamp")
.comparator(comparator)
.makeOrGet();
NavigableSet<Tuple2<Integer, byte[]>> descendingHeightIndex = database.createTreeSet("transactions_index_timestamp_descending")
.comparator(new ReverseComparator(comparator))
.makeOrGet();
createIndex(TIMESTAMP_INDEX, heightIndex, descendingHeightIndex, new Fun.Function2<Long, byte[], Transaction>() {
@Override
public Long run(byte[] key, Transaction value) {
return value.getTimestamp();
}
});
}
示例4: testEqualsPerformance
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Test
public void testEqualsPerformance() {
boolean testEnabled = false;
if (testEnabled) {
final int ITERATIONS = 10000000;
long start1 = System.currentTimeMillis();
for (int i = 0; i < ITERATIONS; i++) {
Comparator<byte[]> comparator = UnsignedBytes
.lexicographicalComparator();
comparator.compare(wrapper1.getData(),
wrapper2.getData());
}
System.out.println(System.currentTimeMillis() - start1 + "ms");
long start2 = System.currentTimeMillis();
for (int i = 0; i < ITERATIONS; i++) {
Arrays.equals(wrapper1.getData(), wrapper2.getData());
}
System.out.println(System.currentTimeMillis() - start2 + "ms");
long start3 = System.currentTimeMillis();
for (int i = 0; i < ITERATIONS; i++) {
FastByteComparisons.compareTo(wrapper1.getData(), 0, wrapper1.getData().length, wrapper2.getData(), 0, wrapper1.getData().length);
}
System.out.println(System.currentTimeMillis() - start3 + "ms");
}
}
示例5: getTxChanges
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override
public Collection<byte[]> getTxChanges() {
if (conflictLevel == TxConstants.ConflictDetection.NONE) {
return Collections.emptyList();
}
Collection<byte[]> txChanges = new TreeSet<byte[]>(UnsignedBytes.lexicographicalComparator());
for (Set<ActionChange> changeSet : changeSets.values()) {
for (ActionChange change : changeSet) {
txChanges.add(getChangeKey(change.getRow(), change.getFamily(), change.getQualifier()));
}
}
return txChanges;
}
示例6: startTx
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override
public void startTx(Transaction tx) {
this.tx = tx;
if (inProgressChanges == null) {
inProgressChanges = new TreeSet<>(UnsignedBytes.lexicographicalComparator());
for (long inProgressTx : tx.getInProgress()) {
inProgressChanges.add(Bytes.concat(fenceId, Longs.toByteArray(inProgressTx)));
}
}
}
示例7: CostEstimator
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
protected CostEstimator(Schema schema, Properties properties, KeyCreator keyCreator,
CostModelFactory modelFactory) {
this.schema = schema;
this.properties = properties;
model = modelFactory.newCostModel(schema, this);
key = keyCreator.createKey();
keyPTarget = new PersistitKeyValueTarget(getClass().getSimpleName());
bytesComparator = UnsignedBytes.lexicographicalComparator();
}
示例8: TransactionDatabase
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
public TransactionDatabase(TransactionDatabase parent)
{
this.parent = parent;
//OPEN MAP
this.transactionMap = new TreeMap<byte[], byte[]>(UnsignedBytes.lexicographicalComparator());
}
示例9: createRedeemScript
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
/**
* Creates redeem script with given public keys and threshold. Given public keys will be placed in
* redeem script in the lexicographical sorting order.
*/
public static Script createRedeemScript(int threshold, List<byte[]> pubkeys) {
pubkeys = new ArrayList<byte[]>(pubkeys);
final Comparator comparator = UnsignedBytes.lexicographicalComparator();
Collections.sort(pubkeys, new Comparator<byte[]>() {
@Override
public int compare(byte[] k1, byte[] k2) {
return comparator.compare(k1, k2);
}
});
return ScriptBuilder.createMultiSigOutputScript(threshold, pubkeys);
}
示例10: testEqualsPerformance
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Test
public void testEqualsPerformance() {
boolean testEnabled = false;
if(testEnabled) {
final int ITERATIONS = 10000000;
long start1 = System.currentTimeMillis();
for (int i = 0; i < ITERATIONS; i++) {
Comparator<byte[]> comparator = UnsignedBytes
.lexicographicalComparator();
comparator.compare(wrapper1.getData(),
wrapper2.getData());
}
System.out.println(System.currentTimeMillis() - start1 + "ms");
long start2 = System.currentTimeMillis();
for (int i = 0; i < ITERATIONS; i++) {
Arrays.equals(wrapper1.getData(), wrapper2.getData());
}
System.out.println(System.currentTimeMillis() - start2 + "ms");
long start3 = System.currentTimeMillis();
for (int i = 0; i < ITERATIONS; i++) {
FastByteComparisons.compareTo(wrapper1.getData(), 0, wrapper1.getData().length, wrapper2.getData(), 0, wrapper1.getData().length);
}
System.out.println(System.currentTimeMillis() - start3 + "ms");
}
}
示例11: TestFieldIndex
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
public TestFieldIndex(int numFields, MiruBitmaps<RoaringBitmap, RoaringBitmap> bitmaps) {
indexes = new NavigableMap[numFields];
this.bitmaps = bitmaps;
for (int i = 0; i < numFields; i++) {
Comparator<byte[]> comparator = UnsignedBytes.lexicographicalComparator();
indexes[i] = new ConcurrentSkipListMap<>((o1, o2) -> {
return comparator.compare(o1.getBytes(), o2.getBytes());
});
}
}
示例12: LongLexicoderTest
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
public LongLexicoderTest() {
super(
Lexicoders.LONG,
Long.MIN_VALUE,
Long.MAX_VALUE,
new Long[] {
-10l,
Long.MIN_VALUE,
2678l,
Long.MAX_VALUE,
0l
},
UnsignedBytes.lexicographicalComparator());
}
示例13: IntegerLexicoderTest
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
public IntegerLexicoderTest() {
super(
Lexicoders.INT,
Integer.MIN_VALUE,
Integer.MAX_VALUE,
new Integer[] {
-10,
Integer.MIN_VALUE,
2678,
Integer.MAX_VALUE,
0
},
UnsignedBytes.lexicographicalComparator());
}
示例14: MapStore
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
public MapStore(String name){
this.map = new ConcurrentSkipListMap<>(UnsignedBytes.lexicographicalComparator());
this.name = name;
}
示例15: compare
import com.google.common.primitives.UnsignedBytes; //导入方法依赖的package包/类
@Override
public int compare(final byte[] o1, final byte[] o2) {
final Comparator<byte[]> c = UnsignedBytes.lexicographicalComparator();
return c.compare(o1, o2);
}