org.bitcoinj.core.Utils.checkBitLE()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(97)

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

Utils.checkBitLE介绍

[英]Checks if the given bit is set in data, using little endian (not the same as Java native big endian)
[中]使用little-endian(与Java原生big-endian不同)检查给定位是否在数据中设置

代码示例

代码示例来源:origin: fr.acinq/bitcoinj-core

  1. /**
  2. * Returns true if the given object matches the filter either because it was inserted, or because we have a
  3. * false-positive.
  4. */
  5. public synchronized boolean contains(byte[] object) {
  6. for (int i = 0; i < hashFuncs; i++) {
  7. if (!Utils.checkBitLE(data, murmurHash3(data, nTweak, i, object)))
  8. return false;
  9. }
  10. return true;
  11. }

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

  1. /**
  2. * Returns true if the given object matches the filter either because it was inserted, or because we have a
  3. * false-positive.
  4. */
  5. public synchronized boolean contains(byte[] object) {
  6. for (int i = 0; i < hashFuncs; i++) {
  7. if (!Utils.checkBitLE(data, murmurHash3(data, nTweak, i, object)))
  8. return false;
  9. }
  10. return true;
  11. }

代码示例来源:origin: greenaddress/GreenBits

  1. /**
  2. * Returns true if the given object matches the filter either because it was inserted, or because we have a
  3. * false-positive.
  4. */
  5. public synchronized boolean contains(byte[] object) {
  6. for (int i = 0; i < hashFuncs; i++) {
  7. if (!Utils.checkBitLE(data, murmurHash3(data, nTweak, i, object)))
  8. return false;
  9. }
  10. return true;
  11. }

代码示例来源:origin: HashEngineering/dashj

  1. /**
  2. * Returns true if the given object matches the filter either because it was inserted, or because we have a
  3. * false-positive.
  4. */
  5. public synchronized boolean contains(byte[] object) {
  6. for (int i = 0; i < hashFuncs; i++) {
  7. if (!Utils.checkBitLE(data, murmurHash3(data, nTweak, i, object)))
  8. return false;
  9. }
  10. return true;
  11. }

代码示例来源:origin: greenaddress/GreenBits

  1. private static void traverseAndBuild(int height, int pos, List<Sha256Hash> allLeafHashes, byte[] includeBits,
  2. List<Boolean> matchedChildBits, List<Sha256Hash> resultHashes) {
  3. boolean parentOfMatch = false;
  4. // Is this node a parent of at least one matched hash?
  5. for (int p = pos << height; p < (pos+1) << height && p < allLeafHashes.size(); p++) {
  6. if (Utils.checkBitLE(includeBits, p)) {
  7. parentOfMatch = true;
  8. break;
  9. }
  10. }
  11. // Store as a flag bit.
  12. matchedChildBits.add(parentOfMatch);
  13. if (height == 0 || !parentOfMatch) {
  14. // If at height 0, or nothing interesting below, store hash and stop.
  15. resultHashes.add(calcHash(height, pos, allLeafHashes));
  16. } else {
  17. // Otherwise descend into the subtrees.
  18. int h = height - 1;
  19. int p = pos * 2;
  20. traverseAndBuild(h, p, allLeafHashes, includeBits, matchedChildBits, resultHashes);
  21. if (p + 1 < getTreeWidth(allLeafHashes.size(), h))
  22. traverseAndBuild(h, p + 1, allLeafHashes, includeBits, matchedChildBits, resultHashes);
  23. }
  24. }

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

  1. private static void traverseAndBuild(int height, int pos, List<Sha256Hash> allLeafHashes, byte[] includeBits,
  2. List<Boolean> matchedChildBits, List<Sha256Hash> resultHashes) {
  3. boolean parentOfMatch = false;
  4. // Is this node a parent of at least one matched hash?
  5. for (int p = pos << height; p < (pos+1) << height && p < allLeafHashes.size(); p++) {
  6. if (Utils.checkBitLE(includeBits, p)) {
  7. parentOfMatch = true;
  8. break;
  9. }
  10. }
  11. // Store as a flag bit.
  12. matchedChildBits.add(parentOfMatch);
  13. if (height == 0 || !parentOfMatch) {
  14. // If at height 0, or nothing interesting below, store hash and stop.
  15. resultHashes.add(calcHash(height, pos, allLeafHashes));
  16. } else {
  17. // Otherwise descend into the subtrees.
  18. int h = height - 1;
  19. int p = pos * 2;
  20. traverseAndBuild(h, p, allLeafHashes, includeBits, matchedChildBits, resultHashes);
  21. if (p + 1 < getTreeWidth(allLeafHashes.size(), h))
  22. traverseAndBuild(h, p + 1, allLeafHashes, includeBits, matchedChildBits, resultHashes);
  23. }
  24. }

代码示例来源:origin: HashEngineering/dashj

  1. private static void traverseAndBuild(int height, int pos, List<Sha256Hash> allLeafHashes, byte[] includeBits,
  2. List<Boolean> matchedChildBits, List<Sha256Hash> resultHashes) {
  3. boolean parentOfMatch = false;
  4. // Is this node a parent of at least one matched hash?
  5. for (int p = pos << height; p < (pos+1) << height && p < allLeafHashes.size(); p++) {
  6. if (Utils.checkBitLE(includeBits, p)) {
  7. parentOfMatch = true;
  8. break;
  9. }
  10. }
  11. // Store as a flag bit.
  12. matchedChildBits.add(parentOfMatch);
  13. if (height == 0 || !parentOfMatch) {
  14. // If at height 0, or nothing interesting below, store hash and stop.
  15. resultHashes.add(calcHash(height, pos, allLeafHashes));
  16. } else {
  17. // Otherwise descend into the subtrees.
  18. int h = height - 1;
  19. int p = pos * 2;
  20. traverseAndBuild(h, p, allLeafHashes, includeBits, matchedChildBits, resultHashes);
  21. if (p + 1 < getTreeWidth(allLeafHashes.size(), h))
  22. traverseAndBuild(h, p + 1, allLeafHashes, includeBits, matchedChildBits, resultHashes);
  23. }
  24. }

代码示例来源:origin: fr.acinq/bitcoinj-core

  1. private static void traverseAndBuild(int height, int pos, List<Sha256Hash> allLeafHashes, byte[] includeBits,
  2. List<Boolean> matchedChildBits, List<Sha256Hash> resultHashes) {
  3. boolean parentOfMatch = false;
  4. // Is this node a parent of at least one matched hash?
  5. for (int p = pos << height; p < (pos+1) << height && p < allLeafHashes.size(); p++) {
  6. if (Utils.checkBitLE(includeBits, p)) {
  7. parentOfMatch = true;
  8. break;
  9. }
  10. }
  11. // Store as a flag bit.
  12. matchedChildBits.add(parentOfMatch);
  13. if (height == 0 || !parentOfMatch) {
  14. // If at height 0, or nothing interesting below, store hash and stop.
  15. resultHashes.add(calcHash(height, pos, allLeafHashes));
  16. } else {
  17. // Otherwise descend into the subtrees.
  18. int h = height - 1;
  19. int p = pos * 2;
  20. traverseAndBuild(h, p, allLeafHashes, includeBits, matchedChildBits, resultHashes);
  21. if (p + 1 < getTreeWidth(allLeafHashes.size(), h))
  22. traverseAndBuild(h, p + 1, allLeafHashes, includeBits, matchedChildBits, resultHashes);
  23. }
  24. }

代码示例来源:origin: fr.acinq/bitcoinj-core

  1. boolean parentOfMatch = checkBitLE(matchedChildBits, used.bitsUsed++);
  2. if (height == 0 || !parentOfMatch) {

代码示例来源:origin: greenaddress/GreenBits

  1. private Sha256Hash recursiveExtractHashes(int height, int pos, ValuesUsed used, List<Sha256Hash> matchedHashes) throws VerificationException {
  2. if (used.bitsUsed >= matchedChildBits.length*8) {
  3. // overflowed the bits array - failure
  4. throw new VerificationException("PartialMerkleTree overflowed its bits array");
  5. }
  6. boolean parentOfMatch = checkBitLE(matchedChildBits, used.bitsUsed++);
  7. if (height == 0 || !parentOfMatch) {
  8. // if at height 0, or nothing interesting below, use stored hash and do not descend
  9. if (used.hashesUsed >= hashes.size()) {
  10. // overflowed the hash array - failure
  11. throw new VerificationException("PartialMerkleTree overflowed its hash array");
  12. }
  13. Sha256Hash hash = hashes.get(used.hashesUsed++);
  14. if (height == 0 && parentOfMatch) // in case of height 0, we have a matched txid
  15. matchedHashes.add(hash);
  16. return hash;
  17. } else {
  18. // otherwise, descend into the subtrees to extract matched txids and hashes
  19. byte[] left = recursiveExtractHashes(height - 1, pos * 2, used, matchedHashes).getBytes(), right;
  20. if (pos * 2 + 1 < getTreeWidth(transactionCount, height-1)) {
  21. right = recursiveExtractHashes(height - 1, pos * 2 + 1, used, matchedHashes).getBytes();
  22. if (Arrays.equals(right, left))
  23. throw new VerificationException("Invalid merkle tree with duplicated left/right branches");
  24. } else {
  25. right = left;
  26. }
  27. // and combine them before returning
  28. return combineLeftRight(left, right);
  29. }
  30. }

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

  1. private Sha256Hash recursiveExtractHashes(int height, int pos, ValuesUsed used, List<Sha256Hash> matchedHashes) throws VerificationException {
  2. if (used.bitsUsed >= matchedChildBits.length*8) {
  3. // overflowed the bits array - failure
  4. throw new VerificationException("PartialMerkleTree overflowed its bits array");
  5. }
  6. boolean parentOfMatch = checkBitLE(matchedChildBits, used.bitsUsed++);
  7. if (height == 0 || !parentOfMatch) {
  8. // if at height 0, or nothing interesting below, use stored hash and do not descend
  9. if (used.hashesUsed >= hashes.size()) {
  10. // overflowed the hash array - failure
  11. throw new VerificationException("PartialMerkleTree overflowed its hash array");
  12. }
  13. Sha256Hash hash = hashes.get(used.hashesUsed++);
  14. if (height == 0 && parentOfMatch) // in case of height 0, we have a matched txid
  15. matchedHashes.add(hash);
  16. return hash;
  17. } else {
  18. // otherwise, descend into the subtrees to extract matched txids and hashes
  19. byte[] left = recursiveExtractHashes(height - 1, pos * 2, used, matchedHashes).getBytes(), right;
  20. if (pos * 2 + 1 < getTreeWidth(transactionCount, height-1)) {
  21. right = recursiveExtractHashes(height - 1, pos * 2 + 1, used, matchedHashes).getBytes();
  22. if (Arrays.equals(right, left))
  23. throw new VerificationException("Invalid merkle tree with duplicated left/right branches");
  24. } else {
  25. right = left;
  26. }
  27. // and combine them before returning
  28. return combineLeftRight(left, right);
  29. }
  30. }

代码示例来源:origin: HashEngineering/dashj

  1. private Sha256Hash recursiveExtractHashes(int height, int pos, ValuesUsed used, List<Sha256Hash> matchedHashes) throws VerificationException {
  2. if (used.bitsUsed >= matchedChildBits.length*8) {
  3. // overflowed the bits array - failure
  4. throw new VerificationException("PartialMerkleTree overflowed its bits array");
  5. }
  6. boolean parentOfMatch = checkBitLE(matchedChildBits, used.bitsUsed++);
  7. if (height == 0 || !parentOfMatch) {
  8. // if at height 0, or nothing interesting below, use stored hash and do not descend
  9. if (used.hashesUsed >= hashes.size()) {
  10. // overflowed the hash array - failure
  11. throw new VerificationException("PartialMerkleTree overflowed its hash array");
  12. }
  13. Sha256Hash hash = hashes.get(used.hashesUsed++);
  14. if (height == 0 && parentOfMatch) // in case of height 0, we have a matched txid
  15. matchedHashes.add(hash);
  16. return hash;
  17. } else {
  18. // otherwise, descend into the subtrees to extract matched txids and hashes
  19. byte[] left = recursiveExtractHashes(height - 1, pos * 2, used, matchedHashes).getBytes(), right;
  20. if (pos * 2 + 1 < getTreeWidth(transactionCount, height-1)) {
  21. right = recursiveExtractHashes(height - 1, pos * 2 + 1, used, matchedHashes).getBytes();
  22. if (Arrays.equals(right, left))
  23. throw new VerificationException("Invalid merkle tree with duplicated left/right branches");
  24. } else {
  25. right = left;
  26. }
  27. // and combine them before returning
  28. return combineLeftRight(left, right);
  29. }
  30. }

相关文章