mirror of https://github.com/apache/cassandra
Merge branch 'cassandra-1.1' into cassandra-1.2
Conflicts: build.xml debian/changelog src/java/org/apache/cassandra/gms/PureRandom.java
This commit is contained in:
commit
7ca9b69703
|
|
@ -30,6 +30,11 @@ calculate_heap_sizes()
|
|||
system_memory_in_mb=`prtconf | awk '/Memory size:/ {print $3}'`
|
||||
system_cpu_cores=`psrinfo | wc -l`
|
||||
;;
|
||||
Darwin)
|
||||
system_memory_in_bytes=`sysctl hw.memsize | awk '{print $2}'`
|
||||
system_memory_in_mb=`expr $system_memory_in_bytes / 1024 / 1024`
|
||||
system_cpu_cores=`sysctl hw.ncpu | awk '{print $2}'`
|
||||
;;
|
||||
*)
|
||||
# assume reasonable defaults for e.g. a modern desktop or
|
||||
# cheap server
|
||||
|
|
|
|||
|
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* 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.
|
||||
*/
|
||||
package org.apache.cassandra.gms;
|
||||
|
||||
import java.util.BitSet;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of a PureRandomNumber generator. Use this class cautiously. Not
|
||||
* for general purpose use. Currently this is used by the Gossiper to choose a random
|
||||
* endpoint to Gossip to.
|
||||
*/
|
||||
|
||||
class PureRandom extends Random
|
||||
{
|
||||
private final BitSet bs = new BitSet();
|
||||
private int lastUb;
|
||||
|
||||
PureRandom()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public int nextInt(int ub)
|
||||
{
|
||||
if (ub <= 0)
|
||||
throw new IllegalArgumentException("ub must be positive");
|
||||
|
||||
if (lastUb != ub)
|
||||
{
|
||||
bs.clear();
|
||||
lastUb = ub;
|
||||
}
|
||||
else if(bs.cardinality() == ub)
|
||||
{
|
||||
bs.clear();
|
||||
}
|
||||
|
||||
int value = super.nextInt(ub);
|
||||
while ( bs.get(value) )
|
||||
{
|
||||
value = super.nextInt(ub);
|
||||
}
|
||||
bs.set(value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Throwable
|
||||
{
|
||||
Random pr = new PureRandom();
|
||||
int ubs[] = new int[]{ 2, 3, 1, 10, 5, 0 };
|
||||
|
||||
for (int ub : ubs)
|
||||
{
|
||||
System.out.println("UB: " + String.valueOf(ub));
|
||||
for (int j = 0; j < 10; j++)
|
||||
{
|
||||
int junk = pr.nextInt(ub);
|
||||
// Do something with junk so JVM doesn't optimize away
|
||||
System.out.println(junk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue