java.lang.Math.floorMod()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(267)

本文整理了Java中java.lang.Math.floorMod()方法的一些代码示例,展示了Math.floorMod()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Math.floorMod()方法的具体详情如下:
包路径:java.lang.Math
类名称:Math
方法名:floorMod

Math.floorMod介绍

暂无

代码示例

代码示例来源:origin: wildfly/wildfly

  1. public String selectNode(final String[] eligibleNodes, final String appName, final String moduleName, final String distinctName) {
  2. final int length = eligibleNodes.length;
  3. assert length > 0;
  4. return eligibleNodes[Math.floorMod(counter.getAndIncrement(), length)];
  5. }
  6. };

代码示例来源:origin: wildfly/wildfly

  1. public URI selectNode(final List<URI> eligibleUris, final EJBLocator<?> locator) {
  2. final int length = eligibleUris.size();
  3. assert length > 0;
  4. return eligibleUris.get(Math.floorMod(counter.getAndIncrement(), length));
  5. }
  6. };

代码示例来源:origin: apache/storm

  1. public static <T> int chooseTaskIndex(List<T> keys, int numTasks) {
  2. return Math.floorMod(listHashCode(keys), numTasks);
  3. }

代码示例来源:origin: wildfly/wildfly

  1. public String selectNode(final String clusterName, final String[] connectedNodes, final String[] totalAvailableNodes) {
  2. return connectedNodes.length > 0 ? connectedNodes[Math.floorMod(count.getAndIncrement(), connectedNodes.length)] : fallback.selectNode(clusterName, connectedNodes, totalAvailableNodes);
  3. }
  4. };

代码示例来源:origin: wildfly/wildfly

  1. public String selectNode(final String clusterName, final String[] connectedNodes, final String[] totalAvailableNodes) {
  2. if (connectedNodes.length == totalAvailableNodes.length) {
  3. // totalAvailableNodes contains all connectedNodes; if their sizes are equal then all nodes must be connected
  4. return fallback.selectNode(clusterName, connectedNodes, totalAvailableNodes);
  5. }
  6. final HashSet<String> connected = new HashSet<>(connectedNodes.length);
  7. Collections.addAll(connected, connectedNodes);
  8. final ArrayList<String> available = new ArrayList<>(totalAvailableNodes.length);
  9. Collections.addAll(available, totalAvailableNodes);
  10. available.removeAll(connected);
  11. assert ! available.isEmpty();
  12. return available.get(Math.floorMod(count.getAndIncrement(), connectedNodes.length));
  13. }
  14. };

代码示例来源:origin: thinkaurelius/titan

  1. private Object convertValue(Object value) throws BackendException {
  2. if (value instanceof Geoshape) {
  3. return GeoToWktConverter.convertToWktString((Geoshape) value);
  4. }
  5. if (value instanceof UUID) {
  6. return value.toString();
  7. }
  8. if(value instanceof Instant) {
  9. if(Math.floorMod(((Instant) value).getNano(), 1000000) != 0) {
  10. throw new IllegalArgumentException("Solr indexes do not support nanoseconds");
  11. }
  12. return new Date(((Instant) value).toEpochMilli());
  13. }
  14. return value;
  15. }

代码示例来源:origin: prestodb/presto

  1. @Benchmark
  2. public long computePositionWithFloorMod()
  3. {
  4. return Math.floorMod(hashcode, hashTableSize);
  5. }

代码示例来源:origin: jtablesaw/tablesaw

  1. public static DayOfWeek getDayOfWeek(int packedDate) {
  2. int dow0 = Math.floorMod((int) toEpochDay(packedDate) + 3, 7);
  3. return DayOfWeek.of(dow0 + 1);
  4. }

代码示例来源:origin: ben-manes/caffeine

  1. private void onAccess(long key) {
  2. sample++;
  3. if (Math.floorMod(hasher.hashLong(key).asInt(), R) < 1) {
  4. for (WindowTinyLfuPolicy policy : minis) {
  5. policy.record(key);
  6. }
  7. }
  8. }

代码示例来源:origin: prestodb/presto

  1. long millisSinceEpoch = (long) value;
  2. long secondsAndNanos = (Math.floorDiv(millisSinceEpoch, 1000L) << 30) + Math.floorMod(millisSinceEpoch, 1000);
  3. return (int) ((secondsAndNanos >>> 32) ^ secondsAndNanos);
  4. default:

代码示例来源:origin: prestodb/presto

  1. long millis = Math.floorMod(value, MILLIS_PER_SECOND);

代码示例来源:origin: jtablesaw/tablesaw

  1. public static int plusMonths(int months, int packedDate) {
  2. if (months == 0) {
  3. return packedDate;
  4. }
  5. byte d = getDayOfMonth(packedDate);
  6. byte m = getMonthValue(packedDate);
  7. short y = getYear(packedDate);
  8. long monthCount = y * 12L + (m - 1);
  9. long calcMonths = monthCount + months;
  10. int newYear = YEAR.checkValidIntValue(Math.floorDiv((int) calcMonths, 12));
  11. int newMonth = Math.floorMod((int) calcMonths, 12) + 1;
  12. return resolvePreviousValid(newYear, newMonth, d);
  13. }

代码示例来源:origin: prestodb/presto

  1. long millisSinceEpoch = prestoType.getLong(block, position);
  2. long secondsAndNanos = (Math.floorDiv(millisSinceEpoch, 1000L) << 30) + Math.floorMod(millisSinceEpoch, 1000);
  3. return (int) ((secondsAndNanos >>> 32) ^ secondsAndNanos);
  4. default:

代码示例来源:origin: org.apache.lucene/lucene-core

  1. private void writeBlock(long[] values, int length, long gcd, GrowableByteArrayDataOutput buffer) throws IOException {
  2. assert length > 0;
  3. long min = values[0];
  4. long max = values[0];
  5. for (int i = 1; i < length; ++i) {
  6. final long v = values[i];
  7. assert Math.floorMod(values[i] - min, gcd) == 0;
  8. min = Math.min(min, v);
  9. max = Math.max(max, v);
  10. }
  11. if (min == max) {
  12. data.writeByte((byte) 0);
  13. data.writeLong(min);
  14. } else {
  15. final int bitsPerValue = DirectWriter.unsignedBitsRequired(max - min);
  16. buffer.reset();
  17. assert buffer.getPosition() == 0;
  18. final DirectWriter w = DirectWriter.getInstance(buffer, length, bitsPerValue);
  19. for (int i = 0; i < length; ++i) {
  20. w.add((values[i] - min) / gcd);
  21. }
  22. w.finish();
  23. data.writeByte((byte) bitsPerValue);
  24. data.writeLong(min);
  25. data.writeInt(buffer.getPosition());
  26. data.writeBytes(buffer.getBytes(), buffer.getPosition());
  27. }
  28. }

代码示例来源:origin: org.elasticsearch/elasticsearch

  1. private DiscoveryNode randomIngestNode() {
  2. final DiscoveryNode[] nodes = ingestNodes;
  3. if (nodes.length == 0) {
  4. throw new IllegalStateException("There are no ingest nodes in this cluster, unable to forward request to an ingest node.");
  5. }
  6. return nodes[Math.floorMod(ingestNodeGenerator.incrementAndGet(), nodes.length)];
  7. }

代码示例来源:origin: org.elasticsearch/elasticsearch

  1. /**
  2. * Returns one of the channels out configured for this handle. The channel is selected in a round-robin
  3. * fashion.
  4. */
  5. <T> T getChannel(List<T> channels) {
  6. if (length == 0) {
  7. throw new IllegalStateException("can't select channel size is 0 for types: " + types);
  8. }
  9. assert channels.size() >= offset + length : "illegal size: " + channels.size() + " expected >= " + (offset + length);
  10. return channels.get(offset + Math.floorMod(counter.incrementAndGet(), length));
  11. }

代码示例来源:origin: org.elasticsearch/elasticsearch

  1. @Override
  2. public boolean accept(BytesRef value) {
  3. return Math.floorMod(StringHelper.murmurhash3_x86_32(value, HASH_PARTITIONING_SEED), incNumPartitions) == incZeroBasedPartition;
  4. }
  5. }

代码示例来源:origin: org.elasticsearch/elasticsearch

  1. @Override
  2. public boolean accept(long value) {
  3. // hash the value to keep even distributions
  4. final long hashCode = BitMixer.mix64(value);
  5. return Math.floorMod(hashCode, incNumPartitions) == incZeroBasedPartition;
  6. }
  7. }

代码示例来源:origin: stackoverflow.com

  1. // use INSTANT_SECONDS, thus this code is not bound by Instant.MAX
  2. Long inSec = context.getValue(INSTANT_SECONDS);
  3. if (inSec >= -SECONDS_0000_TO_1970) {
  4. // current era
  5. long zeroSecs = inSec - SECONDS_PER_10000_YEARS + SECONDS_0000_TO_1970;
  6. long hi = Math.floorDiv(zeroSecs, SECONDS_PER_10000_YEARS) + 1;
  7. long lo = Math.floorMod(zeroSecs, SECONDS_PER_10000_YEARS);
  8. LocalDateTime ldt = LocalDateTime.ofEpochSecond(lo - SECONDS_0000_TO_1970, 0, ZoneOffset.UTC);
  9. if (hi > 0) {
  10. buf.append('+').append(hi);
  11. }
  12. buf.append(ldt);
  13. }

代码示例来源:origin: org.elasticsearch/elasticsearch

  1. private static int calculateScaledShardId(IndexMetaData indexMetaData, String effectiveRouting, int partitionOffset) {
  2. final int hash = Murmur3HashFunction.hash(effectiveRouting) + partitionOffset;
  3. // we don't use IMD#getNumberOfShards since the index might have been shrunk such that we need to use the size
  4. // of original index to hash documents
  5. return Math.floorMod(hash, indexMetaData.getRoutingNumShards()) / indexMetaData.getRoutingFactor();
  6. }

相关文章