public String selectNode(final String[] eligibleNodes, final String appName, final String moduleName, final String distinctName) { final int length = eligibleNodes.length; assert length > 0; return eligibleNodes[Math.floorMod(counter.getAndIncrement(), length)]; } };
public URI selectNode(final List<URI> eligibleUris, final EJBLocator<?> locator) { final int length = eligibleUris.size(); assert length > 0; return eligibleUris.get(Math.floorMod(counter.getAndIncrement(), length)); } };
public static <T> int chooseTaskIndex(List<T> keys, int numTasks) { return Math.floorMod(listHashCode(keys), numTasks); }
public String selectNode(final String clusterName, final String[] connectedNodes, final String[] totalAvailableNodes) { return connectedNodes.length > 0 ? connectedNodes[Math.floorMod(count.getAndIncrement(), connectedNodes.length)] : fallback.selectNode(clusterName, connectedNodes, totalAvailableNodes); } };
public String selectNode(final String clusterName, final String[] connectedNodes, final String[] totalAvailableNodes) { if (connectedNodes.length == totalAvailableNodes.length) { // totalAvailableNodes contains all connectedNodes; if their sizes are equal then all nodes must be connected return fallback.selectNode(clusterName, connectedNodes, totalAvailableNodes); } final HashSet<String> connected = new HashSet<>(connectedNodes.length); Collections.addAll(connected, connectedNodes); final ArrayList<String> available = new ArrayList<>(totalAvailableNodes.length); Collections.addAll(available, totalAvailableNodes); available.removeAll(connected); assert ! available.isEmpty(); return available.get(Math.floorMod(count.getAndIncrement(), connectedNodes.length)); } };
private Object convertValue(Object value) throws BackendException { if (value instanceof Geoshape) { return GeoToWktConverter.convertToWktString((Geoshape) value); } if (value instanceof UUID) { return value.toString(); } if(value instanceof Instant) { if(Math.floorMod(((Instant) value).getNano(), 1000000) != 0) { throw new IllegalArgumentException("Solr indexes do not support nanoseconds"); } return new Date(((Instant) value).toEpochMilli()); } return value; }
@Benchmark public long computePositionWithFloorMod() { return Math.floorMod(hashcode, hashTableSize); }
public static DayOfWeek getDayOfWeek(int packedDate) { int dow0 = Math.floorMod((int) toEpochDay(packedDate) + 3, 7); return DayOfWeek.of(dow0 + 1); }
private void onAccess(long key) { sample++; if (Math.floorMod(hasher.hashLong(key).asInt(), R) < 1) { for (WindowTinyLfuPolicy policy : minis) { policy.record(key); } } }
long millisSinceEpoch = (long) value; long secondsAndNanos = (Math.floorDiv(millisSinceEpoch, 1000L) << 30) + Math.floorMod(millisSinceEpoch, 1000); return (int) ((secondsAndNanos >>> 32) ^ secondsAndNanos); default:
long millis = Math.floorMod(value, MILLIS_PER_SECOND);
public static int plusMonths(int months, int packedDate) { if (months == 0) { return packedDate; } byte d = getDayOfMonth(packedDate); byte m = getMonthValue(packedDate); short y = getYear(packedDate); long monthCount = y * 12L + (m - 1); long calcMonths = monthCount + months; int newYear = YEAR.checkValidIntValue(Math.floorDiv((int) calcMonths, 12)); int newMonth = Math.floorMod((int) calcMonths, 12) + 1; return resolvePreviousValid(newYear, newMonth, d); }
long millisSinceEpoch = prestoType.getLong(block, position); long secondsAndNanos = (Math.floorDiv(millisSinceEpoch, 1000L) << 30) + Math.floorMod(millisSinceEpoch, 1000); return (int) ((secondsAndNanos >>> 32) ^ secondsAndNanos); default:
private void writeBlock(long[] values, int length, long gcd, GrowableByteArrayDataOutput buffer) throws IOException { assert length > 0; long min = values[0]; long max = values[0]; for (int i = 1; i < length; ++i) { final long v = values[i]; assert Math.floorMod(values[i] - min, gcd) == 0; min = Math.min(min, v); max = Math.max(max, v); } if (min == max) { data.writeByte((byte) 0); data.writeLong(min); } else { final int bitsPerValue = DirectWriter.unsignedBitsRequired(max - min); buffer.reset(); assert buffer.getPosition() == 0; final DirectWriter w = DirectWriter.getInstance(buffer, length, bitsPerValue); for (int i = 0; i < length; ++i) { w.add((values[i] - min) / gcd); } w.finish(); data.writeByte((byte) bitsPerValue); data.writeLong(min); data.writeInt(buffer.getPosition()); data.writeBytes(buffer.getBytes(), buffer.getPosition()); } }
private DiscoveryNode randomIngestNode() { final DiscoveryNode[] nodes = ingestNodes; if (nodes.length == 0) { throw new IllegalStateException("There are no ingest nodes in this cluster, unable to forward request to an ingest node."); } return nodes[Math.floorMod(ingestNodeGenerator.incrementAndGet(), nodes.length)]; }
/** * Returns one of the channels out configured for this handle. The channel is selected in a round-robin * fashion. */ <T> T getChannel(List<T> channels) { if (length == 0) { throw new IllegalStateException("can't select channel size is 0 for types: " + types); } assert channels.size() >= offset + length : "illegal size: " + channels.size() + " expected >= " + (offset + length); return channels.get(offset + Math.floorMod(counter.incrementAndGet(), length)); }
@Override public boolean accept(BytesRef value) { return Math.floorMod(StringHelper.murmurhash3_x86_32(value, HASH_PARTITIONING_SEED), incNumPartitions) == incZeroBasedPartition; } }
@Override public boolean accept(long value) { // hash the value to keep even distributions final long hashCode = BitMixer.mix64(value); return Math.floorMod(hashCode, incNumPartitions) == incZeroBasedPartition; } }
// use INSTANT_SECONDS, thus this code is not bound by Instant.MAX Long inSec = context.getValue(INSTANT_SECONDS); if (inSec >= -SECONDS_0000_TO_1970) { // current era long zeroSecs = inSec - SECONDS_PER_10000_YEARS + SECONDS_0000_TO_1970; long hi = Math.floorDiv(zeroSecs, SECONDS_PER_10000_YEARS) + 1; long lo = Math.floorMod(zeroSecs, SECONDS_PER_10000_YEARS); LocalDateTime ldt = LocalDateTime.ofEpochSecond(lo - SECONDS_0000_TO_1970, 0, ZoneOffset.UTC); if (hi > 0) { buf.append('+').append(hi); } buf.append(ldt); }
private static int calculateScaledShardId(IndexMetaData indexMetaData, String effectiveRouting, int partitionOffset) { final int hash = Murmur3HashFunction.hash(effectiveRouting) + partitionOffset; // we don't use IMD#getNumberOfShards since the index might have been shrunk such that we need to use the size // of original index to hash documents return Math.floorMod(hash, indexMetaData.getRoutingNumShards()) / indexMetaData.getRoutingFactor(); }