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

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

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

Math.floorMod介绍

暂无

代码示例

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

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)];
  }
};

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

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));
  }
};

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

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

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

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);
  }
};

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

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));
  }
};

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

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;
}

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

@Benchmark
public long computePositionWithFloorMod()
{
  return Math.floorMod(hashcode, hashTableSize);
}

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

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

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

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

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

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

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

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

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

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);
}

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

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

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

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());
 }
}

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

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)];
}

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

/**
 * 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));
}

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

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

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

@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;
  }
}

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

// 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);
}

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

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();
}

相关文章