Repository: cassandra Updated Branches: refs/heads/trunk 9ccccf28d -> 68d252663
http://git-wip-us.apache.org/repos/asf/cassandra/blob/68d25266/src/java/org/apache/cassandra/utils/FBUtilities.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/FBUtilities.java b/src/java/org/apache/cassandra/utils/FBUtilities.java index 16c17c3..a925c0e 100644 --- a/src/java/org/apache/cassandra/utils/FBUtilities.java +++ b/src/java/org/apache/cassandra/utils/FBUtilities.java @@ -182,10 +182,14 @@ public class FBUtilities public static String getNetworkInterface(InetAddress localAddress) { - try { - for(NetworkInterface ifc : Collections.list(NetworkInterface.getNetworkInterfaces())) { - if(ifc.isUp()) { - for(InetAddress addr : Collections.list(ifc.getInetAddresses())) { + try + { + for(NetworkInterface ifc : Collections.list(NetworkInterface.getNetworkInterfaces())) + { + if(ifc.isUp()) + { + for(InetAddress addr : Collections.list(ifc.getInetAddresses())) + { if (addr.equals(localAddress)) return ifc.getDisplayName(); } @@ -877,7 +881,7 @@ public class FBUtilities throw new RuntimeException(e); } } - + public static void sleepQuietly(long millis) { try http://git-wip-us.apache.org/repos/asf/cassandra/blob/68d25266/src/java/org/apache/cassandra/utils/FastByteOperations.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/FastByteOperations.java b/src/java/org/apache/cassandra/utils/FastByteOperations.java index 02c0dbb..6581736 100644 --- a/src/java/org/apache/cassandra/utils/FastByteOperations.java +++ b/src/java/org/apache/cassandra/utils/FastByteOperations.java @@ -266,7 +266,8 @@ public class FastByteOperations public static void copy(Object src, long srcOffset, Object dst, long dstOffset, long length) { - while (length > 0) { + while (length > 0) + { long size = (length > UNSAFE_COPY_THRESHOLD) ? UNSAFE_COPY_THRESHOLD : length; // if src or dst are null, the offsets are absolute base addresses: theUnsafe.copyMemory(src, srcOffset, dst, dstOffset, size); http://git-wip-us.apache.org/repos/asf/cassandra/blob/68d25266/src/java/org/apache/cassandra/utils/GuidGenerator.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/GuidGenerator.java b/src/java/org/apache/cassandra/utils/GuidGenerator.java index 1e523ea..0843344 100644 --- a/src/java/org/apache/cassandra/utils/GuidGenerator.java +++ b/src/java/org/apache/cassandra/utils/GuidGenerator.java @@ -23,27 +23,33 @@ import java.nio.ByteBuffer; import java.security.SecureRandom; import java.util.Random; -public class GuidGenerator { +public class GuidGenerator +{ private static final Random myRand; private static final SecureRandom mySecureRand; private static final String s_id; - static { - if (System.getProperty("java.security.egd") == null) { + static + { + if (System.getProperty("java.security.egd") == null) + { System.setProperty("java.security.egd", "file:/dev/urandom"); } mySecureRand = new SecureRandom(); long secureInitializer = mySecureRand.nextLong(); myRand = new Random(secureInitializer); - try { + try + { s_id = InetAddress.getLocalHost().toString(); } - catch (UnknownHostException e) { + catch (UnknownHostException e) + { throw new AssertionError(e); } } - public static String guid() { + public static String guid() + { ByteBuffer array = guidAsBytes(); StringBuilder sb = new StringBuilder(); @@ -60,7 +66,8 @@ public class GuidGenerator { public static String guidToString(byte[] bytes) { StringBuilder sb = new StringBuilder(); - for (int j = 0; j < bytes.length; ++j) { + for (int j = 0; j < bytes.length; ++j) + { int b = bytes[j] & 0xFF; if (b < 0x10) sb.append('0'); sb.append(Integer.toHexString(b)); @@ -95,7 +102,8 @@ public class GuidGenerator { * Example: C2FEEEAC-CFCD-11D1-8B05-00600806D9B6 */ - private static String convertToStandardFormat(String valueAfterMD5) { + private static String convertToStandardFormat(String valueAfterMD5) + { String raw = valueAfterMD5.toUpperCase(); StringBuilder sb = new StringBuilder(); sb.append(raw.substring(0, 8)) http://git-wip-us.apache.org/repos/asf/cassandra/blob/68d25266/src/java/org/apache/cassandra/utils/Hex.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/Hex.java b/src/java/org/apache/cassandra/utils/Hex.java index c4b4586..9163067 100644 --- a/src/java/org/apache/cassandra/utils/Hex.java +++ b/src/java/org/apache/cassandra/utils/Hex.java @@ -102,7 +102,8 @@ public class Hex { s = stringConstructor.newInstance(0, c.length, c); } - catch (InvocationTargetException ite) { + catch (InvocationTargetException ite) + { // The underlying constructor failed. Unwrapping the exception. Throwable cause = ite.getCause(); logger.error("Underlying string constructor threw an error: {}", http://git-wip-us.apache.org/repos/asf/cassandra/blob/68d25266/src/java/org/apache/cassandra/utils/IntegerInterval.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/IntegerInterval.java b/src/java/org/apache/cassandra/utils/IntegerInterval.java index 03ad6e0..f600136 100644 --- a/src/java/org/apache/cassandra/utils/IntegerInterval.java +++ b/src/java/org/apache/cassandra/utils/IntegerInterval.java @@ -133,7 +133,7 @@ public class IntegerInterval if (extend > end) end = extend; } - + // record directly preceding our start may extend into us; if it does, we take it as our start int lpos = Arrays.binarySearch(ranges, ((start & 0xFFFFFFFFL) << 32) | 0); // lower (i.e. greatest <) of the start position if (lpos < 0) @@ -147,7 +147,7 @@ public class IntegerInterval --lpos; } } - + newRanges = new long[ranges.length - (rpos - lpos) + 1]; int dest = 0; for (int i = 0; i <= lpos; ++i) http://git-wip-us.apache.org/repos/asf/cassandra/blob/68d25266/src/java/org/apache/cassandra/utils/JMXServerUtils.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/JMXServerUtils.java b/src/java/org/apache/cassandra/utils/JMXServerUtils.java index dad757e..84eb870 100644 --- a/src/java/org/apache/cassandra/utils/JMXServerUtils.java +++ b/src/java/org/apache/cassandra/utils/JMXServerUtils.java @@ -223,7 +223,8 @@ public class JMXServerUtils env.put("com.sun.jndi.rmi.factory.socket", clientFactory); logJmxSslConfig(serverFactory); } - else if (localOnly){ + else if (localOnly) + { env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, new RMIServerSocketFactoryImpl(serverAddress)); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/68d25266/src/java/org/apache/cassandra/utils/JVMStabilityInspector.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/JVMStabilityInspector.java b/src/java/org/apache/cassandra/utils/JVMStabilityInspector.java index e1a109a..a7d9dc5 100644 --- a/src/java/org/apache/cassandra/utils/JVMStabilityInspector.java +++ b/src/java/org/apache/cassandra/utils/JVMStabilityInspector.java @@ -111,7 +111,8 @@ public final class JVMStabilityInspector } @VisibleForTesting - public static Killer replaceKiller(Killer newKiller) { + public static Killer replaceKiller(Killer newKiller) + { Killer oldKiller = JVMStabilityInspector.killer; JVMStabilityInspector.killer = newKiller; return oldKiller; http://git-wip-us.apache.org/repos/asf/cassandra/blob/68d25266/src/java/org/apache/cassandra/utils/MerkleTrees.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/MerkleTrees.java b/src/java/org/apache/cassandra/utils/MerkleTrees.java index b950b3b..0e9b671 100644 --- a/src/java/org/apache/cassandra/utils/MerkleTrees.java +++ b/src/java/org/apache/cassandra/utils/MerkleTrees.java @@ -37,7 +37,7 @@ import org.apache.cassandra.io.util.DataOutputPlus; /** * Wrapper class for handling of multiple MerkleTrees at once. - * + * * The MerkleTree's are divided in Ranges of non-overlapping tokens. */ public class MerkleTrees implements Iterable<Map.Entry<Range<Token>, MerkleTree>> @@ -50,7 +50,7 @@ public class MerkleTrees implements Iterable<Map.Entry<Range<Token>, MerkleTree> /** * Creates empty MerkleTrees object. - * + * * @param partitioner The partitioner to use */ public MerkleTrees(IPartitioner partitioner) @@ -66,7 +66,7 @@ public class MerkleTrees implements Iterable<Map.Entry<Range<Token>, MerkleTree> /** * Get the ranges that these merkle trees covers. - * + * * @return */ public Collection<Range<Token>> ranges() @@ -76,7 +76,7 @@ public class MerkleTrees implements Iterable<Map.Entry<Range<Token>, MerkleTree> /** * Get the partitioner in use. - * + * * @return */ public IPartitioner partitioner() @@ -86,7 +86,7 @@ public class MerkleTrees implements Iterable<Map.Entry<Range<Token>, MerkleTree> /** * Add merkle tree's with the defined maxsize and ranges. - * + * * @param maxsize * @param ranges */ @@ -100,7 +100,7 @@ public class MerkleTrees implements Iterable<Map.Entry<Range<Token>, MerkleTree> /** * Add a MerkleTree with the defined size and range. - * + * * @param maxsize * @param range * @return The created merkle tree. @@ -121,7 +121,7 @@ public class MerkleTrees implements Iterable<Map.Entry<Range<Token>, MerkleTree> /** * Get the MerkleTree.Range responsible for the given token. - * + * * @param t * @return */ @@ -144,7 +144,7 @@ public class MerkleTrees implements Iterable<Map.Entry<Range<Token>, MerkleTree> /** * Init a selected MerkleTree with an even tree distribution. - * + * * @param range */ public void init(Range<Token> range) @@ -154,7 +154,7 @@ public class MerkleTrees implements Iterable<Map.Entry<Range<Token>, MerkleTree> /** * Split the MerkleTree responsible for the given token. - * + * * @param t * @return */ @@ -165,7 +165,7 @@ public class MerkleTrees implements Iterable<Map.Entry<Range<Token>, MerkleTree> /** * Invalidate the MerkleTree responsible for the given token. - * + * * @param t */ @VisibleForTesting @@ -176,7 +176,7 @@ public class MerkleTrees implements Iterable<Map.Entry<Range<Token>, MerkleTree> /** * Get the MerkleTree responsible for the given token range. - * + * * @param range * @return */ @@ -205,7 +205,7 @@ public class MerkleTrees implements Iterable<Map.Entry<Range<Token>, MerkleTree> /** * Get the MerkleTree responsible for the given token. - * + * * @param t * @return The given MerkleTree or null if none exist. */ @@ -248,7 +248,7 @@ public class MerkleTrees implements Iterable<Map.Entry<Range<Token>, MerkleTree> /** * Get an iterator for all the invalids generated by the MerkleTrees. - * + * * @return */ public TreeRangeIterator invalids() @@ -258,7 +258,7 @@ public class MerkleTrees implements Iterable<Map.Entry<Range<Token>, MerkleTree> /** * Log the row count per leaf for all MerkleTrees. - * + * * @param logger */ public void logRowCountPerLeaf(Logger logger) @@ -271,7 +271,7 @@ public class MerkleTrees implements Iterable<Map.Entry<Range<Token>, MerkleTree> /** * Log the row size per leaf for all MerkleTrees. - * + * * @param logger */ public void logRowSizePerLeaf(Logger logger) @@ -307,7 +307,7 @@ public class MerkleTrees implements Iterable<Map.Entry<Range<Token>, MerkleTree> { throw new RuntimeException("Unable to append merkle tree hash to result"); } - + return hashed ? baos.toByteArray() : null; } @@ -360,7 +360,7 @@ public class MerkleTrees implements Iterable<Map.Entry<Range<Token>, MerkleTree> /** * Get the differences between the two sets of MerkleTrees. - * + * * @param ltree * @param rtree * @return http://git-wip-us.apache.org/repos/asf/cassandra/blob/68d25266/src/java/org/apache/cassandra/utils/NoSpamLogger.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/NoSpamLogger.java b/src/java/org/apache/cassandra/utils/NoSpamLogger.java index df3d2e4..bee8c06 100644 --- a/src/java/org/apache/cassandra/utils/NoSpamLogger.java +++ b/src/java/org/apache/cassandra/utils/NoSpamLogger.java @@ -217,7 +217,8 @@ public class NoSpamLogger return NoSpamLogger.this.error(CLOCK.nanoTime(), s, objects); } - public boolean log(Level l, String s, long nowNanos, Object... objects) { + public boolean log(Level l, String s, long nowNanos, Object... objects) + { return NoSpamLogger.this.getStatement(s, minIntervalNanos).log(l, nowNanos, objects); } @@ -231,7 +232,8 @@ public class NoSpamLogger return NoSpamLogger.this.getStatement(key, s, minIntervalNanos); } - public NoSpamLogStatement getStatement(String s, long minInterval, TimeUnit unit) { + public NoSpamLogStatement getStatement(String s, long minInterval, TimeUnit unit) + { return NoSpamLogger.this.getStatement(s, unit.toNanos(minInterval)); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/68d25266/src/java/org/apache/cassandra/utils/ObjectSizes.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/ObjectSizes.java b/src/java/org/apache/cassandra/utils/ObjectSizes.java index 5c2434e..dea2bac 100644 --- a/src/java/org/apache/cassandra/utils/ObjectSizes.java +++ b/src/java/org/apache/cassandra/utils/ObjectSizes.java @@ -1,6 +1,6 @@ package org.apache.cassandra.utils; /* - * + * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -8,16 +8,16 @@ package org.apache.cassandra.utils; * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. - * + * */ http://git-wip-us.apache.org/repos/asf/cassandra/blob/68d25266/src/java/org/apache/cassandra/utils/UUIDGen.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/UUIDGen.java b/src/java/org/apache/cassandra/utils/UUIDGen.java index a72139d..41321ba 100644 --- a/src/java/org/apache/cassandra/utils/UUIDGen.java +++ b/src/java/org/apache/cassandra/utils/UUIDGen.java @@ -233,7 +233,8 @@ public class UUIDGen * @param timestamp milliseconds since Unix epoch * @return */ - private static long fromUnixTimestamp(long timestamp) { + private static long fromUnixTimestamp(long timestamp) + { return fromUnixTimestamp(timestamp, 0L); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/68d25266/src/java/org/apache/cassandra/utils/btree/BTreeRemoval.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/btree/BTreeRemoval.java b/src/java/org/apache/cassandra/utils/btree/BTreeRemoval.java index b72214f..f4d9cd4 100644 --- a/src/java/org/apache/cassandra/utils/btree/BTreeRemoval.java +++ b/src/java/org/apache/cassandra/utils/btree/BTreeRemoval.java @@ -148,7 +148,8 @@ public class BTreeRemoval return result; } - private static Object[] rotateRight(final Object[] node, final int i) { + private static Object[] rotateRight(final Object[] node, final int i) + { final int keyEnd = BTree.getBranchKeyEnd(node); final Object[] nextNode = (Object[]) node[keyEnd + i]; final Object[] rightNeighbour = (Object[]) node[keyEnd + i + 1]; @@ -164,7 +165,8 @@ public class BTreeRemoval return newNextNode; } - private static Object[] rotateLeft(final Object[] node, final int i) { + private static Object[] rotateLeft(final Object[] node, final int i) + { final int keyEnd = BTree.getBranchKeyEnd(node); final Object[] nextNode = (Object[]) node[keyEnd + i]; final Object[] leftNeighbour = (Object[]) node[keyEnd + i - 1]; @@ -252,7 +254,8 @@ public class BTreeRemoval return newNode; } - private static <V> Object[] merge(final Object[] left, final Object[] right, final V nodeKey) { + private static <V> Object[] merge(final Object[] left, final Object[] right, final V nodeKey) + { assert BTree.getKeyEnd(left) == BTree.MINIMAL_NODE_SIZE; assert BTree.getKeyEnd(right) == BTree.MINIMAL_NODE_SIZE; final boolean leaves = BTree.isLeaf(left); http://git-wip-us.apache.org/repos/asf/cassandra/blob/68d25266/src/java/org/apache/cassandra/utils/concurrent/Ref.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/concurrent/Ref.java b/src/java/org/apache/cassandra/utils/concurrent/Ref.java index c3dd8b2..3383186 100644 --- a/src/java/org/apache/cassandra/utils/concurrent/Ref.java +++ b/src/java/org/apache/cassandra/utils/concurrent/Ref.java @@ -341,7 +341,8 @@ public final class Ref<T> implements RefCounted<T> } } - private static final Class<?>[] concurrentIterableClasses = new Class<?>[] { + private static final Class<?>[] concurrentIterableClasses = new Class<?>[] + { ConcurrentLinkedQueue.class, ConcurrentLinkedDeque.class, ConcurrentSkipListSet.class, http://git-wip-us.apache.org/repos/asf/cassandra/blob/68d25266/src/java/org/apache/cassandra/utils/memory/BufferPool.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/memory/BufferPool.java b/src/java/org/apache/cassandra/utils/memory/BufferPool.java index 3458c62..20e6006 100644 --- a/src/java/org/apache/cassandra/utils/memory/BufferPool.java +++ b/src/java/org/apache/cassandra/utils/memory/BufferPool.java @@ -68,7 +68,8 @@ public class BufferPool private static final GlobalPool globalPool = new GlobalPool(); /** A thread local pool of chunks, where chunks come from the global pool */ - private static final FastThreadLocal<LocalPool> localPool = new FastThreadLocal<LocalPool>() { + private static final FastThreadLocal<LocalPool> localPool = new FastThreadLocal<LocalPool>() + { @Override protected LocalPool initialValue() { http://git-wip-us.apache.org/repos/asf/cassandra/blob/68d25266/src/java/org/apache/cassandra/utils/obs/BitUtil.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/obs/BitUtil.java b/src/java/org/apache/cassandra/utils/obs/BitUtil.java index 200ffbf..e04de2b 100644 --- a/src/java/org/apache/cassandra/utils/obs/BitUtil.java +++ b/src/java/org/apache/cassandra/utils/obs/BitUtil.java @@ -20,10 +20,12 @@ package org.apache.cassandra.utils.obs; /** A variety of high efficiency bit twiddling routines. * @lucene.internal */ -final class BitUtil { +final class BitUtil +{ /** Returns the number of bits set in the long */ - public static int pop(long x) { + public static int pop(long x) + { /* Hacker's Delight 32 bit pop function: * http://www.hackersdelight.org/HDcode/newCode/pop_arrayHS.cc * @@ -48,7 +50,8 @@ final class BitUtil { } /*** Returns the number of set bits in an array of longs. */ - public static long pop_array(long A[], int wordOffset, int numWords) { + public static long pop_array(long A[], int wordOffset, int numWords) + { /* * Robert Harley and David Seal's bit counting algorithm, as documented * in the revisions of Hacker's Delight @@ -68,7 +71,8 @@ final class BitUtil { long ones=0, twos=0, fours=0; int i; - for (i = wordOffset; i <= n - 8; i+=8) { + for (i = wordOffset; i <= n - 8; i+=8) + { /*** C macro from Hacker's Delight #define CSA(h,l, a,b,c) \ {unsigned u = a ^ b; unsigned v = c; \ @@ -133,7 +137,8 @@ final class BitUtil { // for (i = i; i < n; i++) // Add in the last elements // tot = tot + pop(A[i]); - if (i<=n-4) { + if (i<=n-4) + { long twosA, twosB, foursA, eights; { long b=A[i], c=A[i+1]; @@ -159,7 +164,8 @@ final class BitUtil { i+=4; } - if (i<=n-2) { + if (i<=n-2) + { long b=A[i], c=A[i+1]; long u=ones ^ b; long twosA=(ones & b)|( u & c); @@ -175,7 +181,8 @@ final class BitUtil { i+=2; } - if (i<n) { + if (i<n) + { tot += pop(A[i]); } @@ -190,14 +197,16 @@ final class BitUtil { /** Returns the popcount or cardinality of the two sets after an intersection. * Neither array is modified. */ - public static long pop_intersect(long A[], long B[], int wordOffset, int numWords) { + public static long pop_intersect(long A[], long B[], int wordOffset, int numWords) + { // generated from pop_array via sed 's/A\[\([^]]*\)\]/\(A[\1] \& B[\1]\)/g' int n = wordOffset+numWords; long tot=0, tot8=0; long ones=0, twos=0, fours=0; int i; - for (i = wordOffset; i <= n - 8; i+=8) { + for (i = wordOffset; i <= n - 8; i+=8) + { long twosA,twosB,foursA,foursB,eights; // CSA(twosA, ones, ones, (A[i] & B[i]), (A[i+1] & B[i+1])) @@ -251,7 +260,8 @@ final class BitUtil { } - if (i<=n-4) { + if (i<=n-4) + { long twosA, twosB, foursA, eights; { long b=(A[i] & B[i]), c=(A[i+1] & B[i+1]); @@ -277,7 +287,8 @@ final class BitUtil { i+=4; } - if (i<=n-2) { + if (i<=n-2) + { long b=(A[i] & B[i]), c=(A[i+1] & B[i+1]); long u=ones ^ b; long twosA=(ones & b)|( u & c); @@ -293,7 +304,8 @@ final class BitUtil { i+=2; } - if (i<n) { + if (i<n) + { tot += pop((A[i] & B[i])); } @@ -308,14 +320,16 @@ final class BitUtil { /** Returns the popcount or cardinality of the union of two sets. * Neither array is modified. */ - public static long pop_union(long A[], long B[], int wordOffset, int numWords) { + public static long pop_union(long A[], long B[], int wordOffset, int numWords) + { // generated from pop_array via sed 's/A\[\([^]]*\)\]/\(A[\1] \| B[\1]\)/g' int n = wordOffset+numWords; long tot=0, tot8=0; long ones=0, twos=0, fours=0; int i; - for (i = wordOffset; i <= n - 8; i+=8) { + for (i = wordOffset; i <= n - 8; i+=8) + { /*** C macro from Hacker's Delight #define CSA(h,l, a,b,c) \ {unsigned u = a ^ b; unsigned v = c; \ @@ -375,7 +389,8 @@ final class BitUtil { } - if (i<=n-4) { + if (i<=n-4) + { long twosA, twosB, foursA, eights; { long b=(A[i] | B[i]), c=(A[i+1] | B[i+1]); @@ -401,7 +416,8 @@ final class BitUtil { i+=4; } - if (i<=n-2) { + if (i<=n-2) + { long b=(A[i] | B[i]), c=(A[i+1] | B[i+1]); long u=ones ^ b; long twosA=(ones & b)|( u & c); @@ -417,7 +433,8 @@ final class BitUtil { i+=2; } - if (i<n) { + if (i<n) + { tot += pop((A[i] | B[i])); } @@ -432,14 +449,16 @@ final class BitUtil { /** Returns the popcount or cardinality of A & ~B * Neither array is modified. */ - public static long pop_andnot(long A[], long B[], int wordOffset, int numWords) { + public static long pop_andnot(long A[], long B[], int wordOffset, int numWords) + { // generated from pop_array via sed 's/A\[\([^]]*\)\]/\(A[\1] \& ~B[\1]\)/g' int n = wordOffset+numWords; long tot=0, tot8=0; long ones=0, twos=0, fours=0; int i; - for (i = wordOffset; i <= n - 8; i+=8) { + for (i = wordOffset; i <= n - 8; i+=8) + { /*** C macro from Hacker's Delight #define CSA(h,l, a,b,c) \ {unsigned u = a ^ b; unsigned v = c; \ @@ -499,7 +518,8 @@ final class BitUtil { } - if (i<=n-4) { + if (i<=n-4) + { long twosA, twosB, foursA, eights; { long b=(A[i] & ~B[i]), c=(A[i+1] & ~B[i+1]); @@ -525,7 +545,8 @@ final class BitUtil { i+=4; } - if (i<=n-2) { + if (i<=n-2) + { long b=(A[i] & ~B[i]), c=(A[i+1] & ~B[i+1]); long u=ones ^ b; long twosA=(ones & b)|( u & c); @@ -541,7 +562,8 @@ final class BitUtil { i+=2; } - if (i<n) { + if (i<n) + { tot += pop((A[i] & ~B[i])); } @@ -553,13 +575,15 @@ final class BitUtil { return tot; } - public static long pop_xor(long A[], long B[], int wordOffset, int numWords) { + public static long pop_xor(long A[], long B[], int wordOffset, int numWords) + { int n = wordOffset+numWords; long tot=0, tot8=0; long ones=0, twos=0, fours=0; int i; - for (i = wordOffset; i <= n - 8; i+=8) { + for (i = wordOffset; i <= n - 8; i+=8) + { /*** C macro from Hacker's Delight #define CSA(h,l, a,b,c) \ {unsigned u = a ^ b; unsigned v = c; \ @@ -619,7 +643,8 @@ final class BitUtil { } - if (i<=n-4) { + if (i<=n-4) + { long twosA, twosB, foursA, eights; { long b=(A[i] ^ B[i]), c=(A[i+1] ^ B[i+1]); @@ -645,7 +670,8 @@ final class BitUtil { i+=4; } - if (i<=n-2) { + if (i<=n-2) + { long b=(A[i] ^ B[i]), c=(A[i+1] ^ B[i+1]); long u=ones ^ b; long twosA=(ones & b)|( u & c); @@ -661,7 +687,8 @@ final class BitUtil { i+=2; } - if (i<n) { + if (i<n) + { tot += pop((A[i] ^ B[i])); } @@ -688,7 +715,8 @@ final class BitUtil { /** Returns number of trailing zeros in a 64 bit long value. */ - public static int ntz(long val) { + public static int ntz(long val) + { // A full binary search to determine the low byte was slower than // a linear search for nextSetBit(). This is most likely because // the implementation of nextSetBit() shifts bits to the right, increasing @@ -704,7 +732,8 @@ final class BitUtil { int lowByte = lower & 0xff; if (lowByte != 0) return ntzTable[lowByte]; - if (lower!=0) { + if (lower!=0) + { lowByte = (lower>>>8) & 0xff; if (lowByte != 0) return ntzTable[lowByte] + 8; lowByte = (lower>>>16) & 0xff; @@ -712,7 +741,9 @@ final class BitUtil { // no need to mask off low byte for the last byte in the 32 bit word // no need to check for zero on the last byte either. return ntzTable[lower>>>24] + 24; - } else { + } + else + { // grab upper 32 bits int upper=(int)(val>>32); lowByte = upper & 0xff; @@ -728,7 +759,8 @@ final class BitUtil { } /** Returns number of trailing zeros in a 32 bit int value. */ - public static int ntz(int val) { + public static int ntz(int val) + { // This implementation does a single binary search at the top level only. // In addition, the case of a non-zero first byte is checked for first // because it is the most common in dense bit arrays. @@ -748,7 +780,8 @@ final class BitUtil { * (only works for x!=0) * <br/> This is an alternate implementation of ntz() */ - public static int ntz2(long x) { + public static int ntz2(long x) + { int n = 0; int y = (int)x; if (y==0) {n+=32; y = (int)(x>>>32); } // the only 64 bit shift necessary @@ -760,7 +793,8 @@ final class BitUtil { /** returns 0 based index of first set bit * <br/> This is an alternate implementation of ntz() */ - public static int ntz3(long x) { + public static int ntz3(long x) + { // another implementation taken from Hackers Delight, extended to 64 bits // and converted to Java. // Many 32 bit ntz algorithms are at http://www.hackersdelight.org/HDcode/ntz.cc @@ -778,17 +812,20 @@ final class BitUtil { /** returns true if v is a power of two or zero*/ - public static boolean isPowerOfTwo(int v) { + public static boolean isPowerOfTwo(int v) + { return ((v & (v-1)) == 0); } /** returns true if v is a power of two or zero*/ - public static boolean isPowerOfTwo(long v) { + public static boolean isPowerOfTwo(long v) + { return ((v & (v-1)) == 0); } /** returns the next highest power of two, or the current value if it's already a power of two or zero*/ - public static int nextHighestPowerOfTwo(int v) { + public static int nextHighestPowerOfTwo(int v) + { v--; v |= v >> 1; v |= v >> 2; @@ -800,7 +837,8 @@ final class BitUtil { } /** returns the next highest power of two, or the current value if it's already a power of two or zero*/ - public static long nextHighestPowerOfTwo(long v) { + public static long nextHighestPowerOfTwo(long v) + { v--; v |= v >> 1; v |= v >> 2; http://git-wip-us.apache.org/repos/asf/cassandra/blob/68d25266/src/java/org/apache/cassandra/utils/obs/OpenBitSet.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/obs/OpenBitSet.java b/src/java/org/apache/cassandra/utils/obs/OpenBitSet.java index 82e6929..a21729a 100644 --- a/src/java/org/apache/cassandra/utils/obs/OpenBitSet.java +++ b/src/java/org/apache/cassandra/utils/obs/OpenBitSet.java @@ -85,7 +85,8 @@ public class OpenBitSet implements IBitSet bits[bits.length - 1] = new long[lastPageSize]; } - public OpenBitSet() { + public OpenBitSet() + { this(64); } @@ -124,12 +125,14 @@ public class OpenBitSet implements IBitSet * Returns the current capacity of this set. Included for * compatibility. This is *not* equal to {@link #cardinality} */ - public long size() { + public long size() + { return capacity(); } // @Override -- not until Java 1.6 - public long length() { + public long length() + { return capacity(); } @@ -145,7 +148,8 @@ public class OpenBitSet implements IBitSet * Returns true or false for the specified bit index. * The index should be less than the OpenBitSet size */ - public boolean get(int index) { + public boolean get(int index) + { int i = index >> 6; // div 64 // signed shift will keep a negative index and force an // array-index-out-of-bounds-exception, removing the need for an explicit check. @@ -159,7 +163,8 @@ public class OpenBitSet implements IBitSet * Returns true or false for the specified bit index. * The index should be less than the OpenBitSet size. */ - public boolean get(long index) { + public boolean get(long index) + { int i = (int)(index >> 6); // div 64 int bit = (int)index & 0x3f; // mod 64 long bitmask = 1L << bit; @@ -171,7 +176,8 @@ public class OpenBitSet implements IBitSet * Sets the bit at the specified index. * The index should be less than the OpenBitSet size. */ - public void set(long index) { + public void set(long index) + { int wordNum = (int)(index >> 6); int bit = (int)index & 0x3f; long bitmask = 1L << bit; @@ -182,7 +188,8 @@ public class OpenBitSet implements IBitSet * Sets the bit at the specified index. * The index should be less than the OpenBitSet size. */ - public void set(int index) { + public void set(int index) + { int wordNum = index >> 6; // div 64 int bit = index & 0x3f; // mod 64 long bitmask = 1L << bit; @@ -193,7 +200,8 @@ public class OpenBitSet implements IBitSet * clears a bit. * The index should be less than the OpenBitSet size. */ - public void clear(int index) { + public void clear(int index) + { int wordNum = index >> 6; int bit = index & 0x03f; long bitmask = 1L << bit; @@ -211,7 +219,8 @@ public class OpenBitSet implements IBitSet * clears a bit. * The index should be less than the OpenBitSet size. */ - public void clear(long index) { + public void clear(long index) + { int wordNum = (int)(index >> 6); // div 64 int bit = (int)index & 0x3f; // mod 64 long bitmask = 1L << bit; @@ -224,7 +233,8 @@ public class OpenBitSet implements IBitSet * @param startIndex lower index * @param endIndex one-past the last bit to clear */ - public void clear(int startIndex, int endIndex) { + public void clear(int startIndex, int endIndex) + { if (endIndex <= startIndex) return; int startWord = (startIndex>>6); @@ -241,7 +251,8 @@ public class OpenBitSet implements IBitSet startmask = ~startmask; endmask = ~endmask; - if (startWord == endWord) { + if (startWord == endWord) + { bits[startWord / PAGE_SIZE][startWord % PAGE_SIZE] &= (startmask | endmask); return; } @@ -258,7 +269,8 @@ public class OpenBitSet implements IBitSet while (++startWord<middle) bits[startWord / PAGE_SIZE][startWord % PAGE_SIZE] = 0L; } - if (endWord < wlen) { + if (endWord < wlen) + { bits[endWord / PAGE_SIZE][endWord % PAGE_SIZE] &= endmask; } } @@ -269,7 +281,8 @@ public class OpenBitSet implements IBitSet * @param startIndex lower index * @param endIndex one-past the last bit to clear */ - public void clear(long startIndex, long endIndex) { + public void clear(long startIndex, long endIndex) + { if (endIndex <= startIndex) return; int startWord = (int)(startIndex>>6); @@ -286,7 +299,8 @@ public class OpenBitSet implements IBitSet startmask = ~startmask; endmask = ~endmask; - if (startWord == endWord) { + if (startWord == endWord) +{ bits[startWord / PAGE_SIZE][startWord % PAGE_SIZE] &= (startmask | endmask); return; } @@ -302,7 +316,8 @@ public class OpenBitSet implements IBitSet while (++startWord<middle) bits[startWord / PAGE_SIZE][startWord % PAGE_SIZE] = 0L; } - if (endWord < wlen) { + if (endWord < wlen) + { bits[endWord / PAGE_SIZE][endWord % PAGE_SIZE] &= endmask; } } @@ -318,7 +333,8 @@ public class OpenBitSet implements IBitSet } /** this = this AND other */ - public void intersect(OpenBitSet other) { + public void intersect(OpenBitSet other) + { int newLen= Math.min(this.wlen,other.wlen); long[][] thisArr = this.bits; long[][] otherArr = other.bits; @@ -326,11 +342,13 @@ public class OpenBitSet implements IBitSet int otherPageSize = OpenBitSet.PAGE_SIZE; // testing against zero can be more efficient int pos=newLen; - while(--pos>=0) { + while(--pos>=0) + { thisArr[pos / thisPageSize][ pos % thisPageSize] &= otherArr[pos / otherPageSize][pos % otherPageSize]; } - if (this.wlen > newLen) { + if (this.wlen > newLen) + { // fill zeros from the new shorter length to the old length for (pos=wlen;pos-->newLen;) thisArr[pos / thisPageSize][ pos % thisPageSize] =0; @@ -341,35 +359,42 @@ public class OpenBitSet implements IBitSet // some BitSet compatability methods //** see {@link intersect} */ - public void and(OpenBitSet other) { + public void and(OpenBitSet other) + { intersect(other); } /** Lowers numWords, the number of words in use, * by checking for trailing zero words. */ - public void trimTrailingZeros() { + public void trimTrailingZeros() + { int idx = wlen-1; while (idx>=0 && bits[idx / PAGE_SIZE][idx % PAGE_SIZE]==0) idx--; wlen = idx+1; } /** returns the number of 64 bit words it would take to hold numBits */ - public static long bits2words(long numBits) { + public static long bits2words(long numBits) + { return (((numBits-1)>>>6)+1); } /** returns true if both sets have the same bits set */ @Override - public boolean equals(Object o) { + public boolean equals(Object o) + { if (this == o) return true; if (!(o instanceof OpenBitSet)) return false; OpenBitSet a; OpenBitSet b = (OpenBitSet)o; // make a the larger set. - if (b.wlen > this.wlen) { + if (b.wlen > this.wlen) + { a = b; b=this; - } else { + } + else + { a=this; } @@ -377,11 +402,13 @@ public class OpenBitSet implements IBitSet int bPageSize = OpenBitSet.PAGE_SIZE; // check for any set bits out of the range of b - for (int i=a.wlen-1; i>=b.wlen; i--) { + for (int i=a.wlen-1; i>=b.wlen; i--) + { if (a.bits[i/aPageSize][i % aPageSize]!=0) return false; } - for (int i=b.wlen-1; i>=0; i--) { + for (int i=b.wlen-1; i>=0; i--) + { if (a.bits[i/aPageSize][i % aPageSize] != b.bits[i/bPageSize][i % bPageSize]) return false; } @@ -390,11 +417,13 @@ public class OpenBitSet implements IBitSet @Override - public int hashCode() { + public int hashCode() + { // Start with a zero hash and use a mix that results in zero if the input is zero. // This effectively truncates trailing zeros without an explicit check. long h = 0; - for (int i = wlen; --i>=0;) { + for (int i = wlen; --i>=0;) + { h ^= bits[i / PAGE_SIZE][i % PAGE_SIZE]; h = (h << 1) | (h >>> 63); // rotate left } @@ -403,31 +432,37 @@ public class OpenBitSet implements IBitSet return (int)((h>>32) ^ h) + 0x98761234; } - public void close() { + public void close() + { // noop, let GC do the cleanup. } - public void serialize(DataOutput out) throws IOException { + public void serialize(DataOutput out) throws IOException + { int bitLength = getNumWords(); int pageSize = getPageSize(); int pageCount = getPageCount(); out.writeInt(bitLength); - for (int p = 0; p < pageCount; p++) { + for (int p = 0; p < pageCount; p++) + { long[] bits = getPage(p); - for (int i = 0; i < pageSize && bitLength-- > 0; i++) { + for (int i = 0; i < pageSize && bitLength-- > 0; i++) + { out.writeLong(bits[i]); } } } - public long serializedSize() { + public long serializedSize() + { int bitLength = getNumWords(); int pageSize = getPageSize(); int pageCount = getPageCount(); long size = TypeSizes.sizeof(bitLength); // length - for (int p = 0; p < pageCount; p++) { + for (int p = 0; p < pageCount; p++) + { long[] bits = getPage(p); for (int i = 0; i < pageSize && bitLength-- > 0; i++) size += TypeSizes.sizeof(bits[i]); // bucket @@ -435,18 +470,21 @@ public class OpenBitSet implements IBitSet return size; } - public void clear() { + public void clear() + { clear(0, capacity()); } - public static OpenBitSet deserialize(DataInput in) throws IOException { + public static OpenBitSet deserialize(DataInput in) throws IOException + { long bitLength = in.readInt(); OpenBitSet bs = new OpenBitSet(bitLength << 6); int pageSize = bs.getPageSize(); int pageCount = bs.getPageCount(); - for (int p = 0; p < pageCount; p++) { + for (int p = 0; p < pageCount; p++) + { long[] bits = bs.getPage(p); for (int i = 0; i < pageSize && bitLength-- > 0; i++) bits[i] = in.readLong(); http://git-wip-us.apache.org/repos/asf/cassandra/blob/68d25266/src/java/org/apache/cassandra/utils/vint/VIntCoding.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/utils/vint/VIntCoding.java b/src/java/org/apache/cassandra/utils/vint/VIntCoding.java index 3872424..b490b97 100644 --- a/src/java/org/apache/cassandra/utils/vint/VIntCoding.java +++ b/src/java/org/apache/cassandra/utils/vint/VIntCoding.java @@ -60,7 +60,8 @@ import net.nicoulaj.compilecommand.annotations.Inline; public class VIntCoding { - public static long readUnsignedVInt(DataInput input) throws IOException { + public static long readUnsignedVInt(DataInput input) throws IOException + { int firstByte = input.readByte(); //Bail out early if this is one byte, necessary or it fails later @@ -79,7 +80,8 @@ public class VIntCoding return retval; } - public static long readVInt(DataInput input) throws IOException { + public static long readVInt(DataInput input) throws IOException + { return decodeZigZag64(readUnsignedVInt(input)); } @@ -113,7 +115,8 @@ public class VIntCoding } }; - public static void writeUnsignedVInt(long value, DataOutput output) throws IOException { + public static void writeUnsignedVInt(long value, DataOutput output) throws IOException + { int size = VIntCoding.computeUnsignedVIntSize(value); if (size == 1) { @@ -125,7 +128,8 @@ public class VIntCoding } @Inline - public static byte[] encodeVInt(long value, int size) { + public static byte[] encodeVInt(long value, int size) + { byte encodingSpace[] = encodingBuffer.get(); int extraBytes = size - 1; @@ -138,7 +142,8 @@ public class VIntCoding return encodingSpace; } - public static void writeVInt(long value, DataOutput output) throws IOException { + public static void writeVInt(long value, DataOutput output) throws IOException + { writeUnsignedVInt(encodeZigZag64(value), output); } @@ -152,7 +157,8 @@ public class VIntCoding * Java has no explicit unsigned support. * @return A signed 64-bit integer. */ - public static long decodeZigZag64(final long n) { + public static long decodeZigZag64(final long n) + { return (n >>> 1) ^ -(n & 1); } @@ -166,18 +172,21 @@ public class VIntCoding * @return An unsigned 64-bit integer, stored in a signed int because * Java has no explicit unsigned support. */ - public static long encodeZigZag64(final long n) { + public static long encodeZigZag64(final long n) + { // Note: the right-shift must be arithmetic return (n << 1) ^ (n >> 63); } /** Compute the number of bytes that would be needed to encode a varint. */ - public static int computeVIntSize(final long param) { + public static int computeVIntSize(final long param) + { return computeUnsignedVIntSize(encodeZigZag64(param)); } /** Compute the number of bytes that would be needed to encode an unsigned varint. */ - public static int computeUnsignedVIntSize(final long value) { + public static int computeUnsignedVIntSize(final long value) + { int magnitude = Long.numberOfLeadingZeros(value | 1); // | with 1 to ensure magntiude <= 63, so (63 - 1) / 7 <= 8 return 9 - ((magnitude - 1) / 7); }
