Implementation of FNV-1a hash algorithm.
@see <a href="https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function">
ttps://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function</a>
@param doc the document to hash
@return
432185
public static long hash(final BsonDocument doc) {
    if (doc == null) {
      return 0L;
    }

    final byte[] docBytes = toBytes(doc);
    long hashValue = FNV_64BIT_OFFSET_BASIS;

    for (int offset = 0; offset < docBytes.length; offset++) {
      hashValue ^= (0xFF & docBytes[offset]);
      hashValue *= FNV_64BIT_PRIME;
    }

    return hashValue;
  }
298407
def hash(filepath, method='sha1', buffer_size=65536):
    
    if method == 'sha1':
        hash_function = hashlib.sha1()
    elif method == 'md5':
        hash_function = hashlib.md5()
    else:
        raise NotImplementedError('Only md5 and sha1 hashes are known, but '
                                  ' \'{}\' was specified.'.format(method))

    with open(filepath, 'rb') as fp:
        while True:
            data = fp.read(buffer_size)
            if not data:
                break
            hash_function.update(data)
    return hash_function.hexdigest()
852121
def hash( key, seed = 0x0 ):
    '''  '''

    key = bytearray( xencode(key) )

    def fmix( h ):
        h ^= h >> 16
        h  = ( h * 0x85ebca6b ) & 0xFFFFFFFF
        h ^= h >> 13
        h  = ( h * 0xc2b2ae35 ) & 0xFFFFFFFF
        h ^= h >> 16
        return h

    length = len( key )
    nblocks = int( length / 4 )

    h1 = seed

    c1 = 0xcc9e2d51
    c2 = 0x1b873593

    # body
    for block_start in xrange( 0, nblocks * 4, 4 ):
        # ??? big endian?
        k1 = key[ block_start + 3 ] << 24 | \
             key[ block_start + 2 ] << 16 | \
             key[ block_start + 1 ] <<  8 | \
             key[ block_start + 0 ]
             
        k1 = ( c1 * k1 ) & 0xFFFFFFFF
        k1 = ( k1 << 15 | k1 >> 17 ) & 0xFFFFFFFF # inlined ROTL32
        k1 = ( c2 * k1 ) & 0xFFFFFFFF
        
        h1 ^= k1
        h1  = ( h1 << 13 | h1 >> 19 ) & 0xFFFFFFFF # inlined ROTL32
        h1  = ( h1 * 5 + 0xe6546b64 ) & 0xFFFFFFFF

    # tail
    tail_index = nblocks * 4
    k1 = 0
    tail_size = length & 3

    if tail_size >= 3:
        k1 ^= key[ tail_index + 2 ] << 16
    if tail_size >= 2:
        k1 ^= key[ tail_index + 1 ] << 8
    if tail_size >= 1:
        k1 ^= key[ tail_index + 0 ]
    
    if tail_size > 0:
        k1  = ( k1 * c1 ) & 0xFFFFFFFF
        k1  = ( k1 << 15 | k1 >> 17 ) & 0xFFFFFFFF # inlined ROTL32
        k1  = ( k1 * c2 ) & 0xFFFFFFFF
        h1 ^= k1

    #finalization
    unsigned_val = fmix( h1 ^ length )
    if unsigned_val & 0x80000000 == 0:
        return unsigned_val
    else:
        return -( (unsigned_val ^ 0xFFFFFFFF) + 1 )
72897
private static String sha1hash(Collection<String> nquads) {
        try {
            // create SHA-1 digest
            final MessageDigest md = MessageDigest.getInstance("SHA-1");
            for (final String nquad : nquads) {
                md.update(nquad.getBytes("UTF-8"));
            }
            return encodeHex(md.digest());
        } catch (final NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        } catch (final UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }
401432
public void setDocumentation(String doc) {
		if (Strings.isEmpty(doc)) {
			getSarlAnnotationType().eAdapters().removeIf(new Predicate<Adapter>() {
				public boolean test(Adapter adapter) {
					return adapter.isAdapterForType(DocumentationAdapter.class);
				}
			});
		} else {
			DocumentationAdapter adapter = (DocumentationAdapter) EcoreUtil.getExistingAdapter(
					getSarlAnnotationType(), DocumentationAdapter.class);
			if (adapter == null) {
				adapter = new DocumentationAdapter();
				getSarlAnnotationType().eAdapters().add(adapter);
			}
			adapter.setDocumentation(doc);
		}
	}
957927
public SolrInputDocument buildSolrDocument(HashMap<String, Object> hshMap)
			throws Exception {

		SolrInputDocument doc = new SolrInputDocument();

		Iterator<String> keys = hshMap.keySet().iterator();
		while (keys.hasNext()) {
			String key = keys.next();
			Object value = hshMap.get(key);

			SolrInputField field = new SolrInputField(key);
			try {

				doc.addField(field.getName(), value, 1.0f);

			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		return doc;

	}
1334271
@SuppressWarnings("deprecation")
	public final static HashFunction forName(final String messageDigest) throws NoSuchAlgorithmException {
		if ("".equals(messageDigest)) return null;
		if ("MD5".equalsIgnoreCase(messageDigest)) return Hashing.md5();
		if ("MurmurHash3".equalsIgnoreCase(messageDigest)) return Hashing.murmur3_128();
		throw new NoSuchAlgorithmException("Unknown hash function " + messageDigest);
	}
245173
private KeyScope readScopes(final Document doc) {
        final List<KeyScope> scopes = readScopes(doc.getDocumentElement());
        if (scopes.size() == 1 && scopes.get(0).name == null) {
            return scopes.get(0);
        } else {
            return new KeyScope("#root", null, Collections.emptyMap(), scopes);
        }
    }
248156
def _sighash_final_hashing(self, copy_tx, sighash_type):
        '''
        
        '''
        sighash = z.ZcashByteData()
        sighash += copy_tx.to_bytes()
        sighash += utils.i2le_padded(sighash_type, 4)
        return utils.hash256(sighash.to_bytes())
870995
private String determineHashes(HashingFunction hashFunction) {
        if (isVirtual) {
            return null;
        }
        try {
            final File file = getActualFile();
            return hashFunction.hash(file);
        } catch (IOException | RuntimeException ex) {
            LOGGER.warn("Unable to read '{}' to determine hashes.", actualFilePath);
            LOGGER.debug("", ex);
        } catch (NoSuchAlgorithmException ex) {
            LOGGER.warn("Unable to use MD5 or SHA1 checksums.");
            LOGGER.debug("", ex);
        }
        return null;
    }
242761
def _sighash_final_hashing(self, copy_tx, sighash_type):
        '''
        
        '''
        sighash = ByteData()
        sighash += copy_tx.to_bytes()
        sighash += utils.i2le_padded(sighash_type, 4)

        return utils.hash256(sighash.to_bytes())
107087
public BsonDocument toBsonDocument() {
    final BsonDocument asDoc = new BsonDocument();
    asDoc.put(Fields.OPERATION_TYPE_FIELD, new BsonString(getOperationType().toRemote()));
    asDoc.put(Fields.DOCUMENT_KEY_FIELD, getDocumentKey());

    if (getFullDocument() != null && (getFullDocument() instanceof BsonValue)
        && ((BsonValue) getFullDocument()).isDocument()) {
      asDoc.put(Fields.FULL_DOCUMENT_FIELD, (BsonValue) getFullDocument());
    }

    if (getUpdateDescription() != null) {
      asDoc.put(Fields.UPDATE_DESCRIPTION_FIELD, getUpdateDescription().toBsonDocument());
    }

    if (stitchDocumentVersion != null) {
      asDoc.put(Fields.STITCH_DOCUMENT_VERSION_FIELD, stitchDocumentVersion.toBsonDocument());
    }

    if (stitchDocumentHash != null) {
      asDoc.put(Fields.STITCH_DOCUMENT_HASH_FIELD, new BsonInt64(stitchDocumentHash));
    }

    asDoc.put(Fields.WRITE_PENDING_FIELD, new BsonBoolean(hasUncommittedWrites()));
    return asDoc;
  }
861949
private int hashinateBytes(Object obj) {
        byte[] bytes = VoltType.valueToBytes(obj);
        if (bytes == null) {
            return 0;
        }

        ByteBuffer buf = ByteBuffer.wrap(bytes);
        final int hash = MurmurHash3.hash3_x64_128(buf, 0, bytes.length, 0);
        long token = getTokenPtr(hash);
        return Bits.unsafe.getInt(token + 4);
    }
65377
def checksum(symbol, doc):
    
    sha = hashlib.sha1()
    sha.update(symbol.encode('ascii'))
    for k in sorted(iter(doc.keys()), reverse=True):
        v = doc[k]
        if isinstance(v, six.binary_type):
            sha.update(doc[k])
        else:
            sha.update(str(doc[k]).encode('ascii'))
    return Binary(sha.digest())
1158499
protected void parseAvps(Document doc) {
    // Format:  <avpdefn name="Talk-Burst-Volume" code="1256" vendor-id="TGPP" mandatory="must" protected="may" may-encrypt="true" vendor-bit="must" >
    //            <type type-name="Unsigned32" />
    //          </avpdefn>

    NodeList avpDefnNodes = doc.getElementsByTagName("avpdefn");

    for (int i = 0; i < avpDefnNodes.getLength(); i++) {
      Node avpNode = avpDefnNodes.item(i);
      Element avpDefnElement = (Element) avpNode;

      String avpName = avpDefnElement.getAttribute("name");
      String avpCode = avpDefnElement.getAttribute("code");
      String avpVendorId = avpDefnElement.getAttribute("vendor-id");

      String avpMandatory = avpDefnElement.getAttribute("mandatory");
      String avpProtected = avpDefnElement.getAttribute("protected").equals("") ? "may" : avpDefnElement.getAttribute("protected");
      String avpMayEncrypt = avpDefnElement.getAttribute("may-encrypt");
      String avpVendorBit = avpDefnElement.getAttribute("vendor-bit");

      long vendorCode = getVendorCode(avpVendorId);

      // Let's figure out the type
      // It can be:
      // <type type-name="UTF8String" />
      //  OR
      // <grouped> <avp name="PoC-Change-Time" multiplicity="1" /> ... </grouped>
      //  OR
      // <type type-name="Enumerated"> <enum code="0" name="MULTICAST" /> ... </enumerated>
      String avpOriginalType = UNDEFINED_AVP_TYPE;
      String avpType = avpOriginalType;
      List<AvpRepresentation> groupedAvpChilds = new ArrayList<AvpRepresentation>();

      NodeList avpDefnChildNodes = avpNode.getChildNodes();
      for (int j = 0; j < avpDefnChildNodes.getLength(); j++) {
        Node avpDefnChildNode = avpDefnChildNodes.item(j);

        if (avpDefnChildNode.getNodeType() == Node.ELEMENT_NODE) {
          Element avpDefnChildElement = (Element) avpDefnChildNode;

          if (avpDefnChildElement.getNodeName().equals("grouped")) {
            avpOriginalType = "Grouped";
            avpType = avpOriginalType;

            // Let's fetch the childs
            // Format: <avp name="PoC-Change-Time" multiplicity="1" />
            NodeList groupedAvpMembers = avpDefnChildElement.getChildNodes();

            for (int gChildIndex = 0; gChildIndex < groupedAvpMembers.getLength(); gChildIndex++) {
              Node groupedAvpChildNode = groupedAvpMembers.item(gChildIndex);

              if (groupedAvpChildNode.getNodeType() == Node.ELEMENT_NODE) {
                Element groupedAvpChildElement = (Element) groupedAvpChildNode;

                String childName = null;
                String childMultiplicity = AVP_DEFAULT_MULTIPLICITY;
                String childIndexIndicator = AVP_DEFAULT_INDEX;

                if (!groupedAvpChildElement.hasAttribute("name")) {
                  if (logger.isDebugEnabled()) {
                    logger.debug(new StringBuffer("[ERROR] Grouped child does not have name, grouped avp:  Name[").append(avpName).append("] Description[")
                        .append("").append("] Code[").append(avpCode).append("] May-Encrypt[").append(avpMayEncrypt).append("] Mandatory[")
                        .append(avpMandatory).append("] Protected [").append(avpProtected).append("] Vendor-Bit [").append(avpVendorBit).append("] Vendor-Id [")
                        .append(avpVendorId).append("] Constrained[").append("").append("] Type [").append(avpType).append("]").toString());
                  }
                  continue;
                }
                else {
                  childName = groupedAvpChildElement.getAttribute("name");
                }

                childMultiplicity = groupedAvpChildElement.hasAttribute("multiplicity") ?
                    groupedAvpChildElement.getAttribute("multiplicity") : AvpRepresentation._MP_ZERO_OR_MORE;

                childIndexIndicator = groupedAvpChildElement.hasAttribute("index") ?
                        groupedAvpChildElement.getAttribute("index") : "-1";

                // have we parsed this child definition already?
                AvpRepresentation childRep = this.avpByNameMap.get(childName);
                AvpRepresentationImpl child = null;
                if (childRep != null) {
                  try {
                    child = (AvpRepresentationImpl) childRep.clone();
                  }
                  catch (CloneNotSupportedException cnse) {
                    // It should not happen, but anyway
                    if (logger.isWarnEnabled()) {
                      logger.warn("Unable to clone AVP " + childRep, cnse);
                    }
                  }
                }
                else {
                  child = new AvpRepresentationImpl(childName, vendorCode);
                  child.markWeak(true);
                }
                child.setMultiplicityIndicator(childMultiplicity);
                child.markFixPosition(Integer.valueOf(childIndexIndicator));

                groupedAvpChilds.add(child);
              }
            }
          }
          else if (avpDefnChildElement.getNodeName().equals("type")) {
            avpOriginalType = avpDefnChildElement.getAttribute("type-name");
            avpType = avpOriginalType;
            //FIXME: baranowb: why this is like that? This changes type of AVP to primitive ONE..? Checks against type dont make sense, ie to check for Address type...
            avpType = typedefMap.get(avpType);

            if (avpType == null) {
              logger.warn("Unknown AVP Type ({}) for AVP with code {} and vendor-id {} ",
                  new Object[] { avpDefnChildElement.getAttribute("type-name"), avpCode, avpVendorId});
            }
          }
          else {
            logger.warn("Unknown AVP Definition child element for AVP with code {} and vendor-id {} ", avpCode, avpVendorId);
          }
        }
      }

      try {
        AvpRepresentationImpl avp = null;

        avp = new AvpRepresentationImpl(avpName, "N/A", Integer.valueOf(avpCode), avpMayEncrypt.equals("yes"), avpMandatory,
            avpProtected, avpVendorBit, vendorCode, avpOriginalType, avpType);

        if (avp.isGrouped()) {
          avp.setChildren(groupedAvpChilds);

          // we are not strong enough, children are referenced ONLY by name, so we are
          // weak until all children can be resolved to strong representation
          avp.markWeak(true);
        }

        resolveWeakLinks(avp);

        AvpRepresentation existingAvp = null;
        if ((existingAvp = avpMap.get(avp)) != null) {
          logger.warn("Duplicated AVP Definition for AVP Code: {}, Vendor-Id: {}. See TRACE logs for definitions.", avp.getCode(), avp.getVendorId());
          logger.trace("Existing AVP:\r\n {}\r\n New AVP:\r\n {}", existingAvp, avp);
        }
        else {
          avpMap.put(avp, avp);
        }

        AvpRepresentation oldAvp = avpByNameMap.put(avp.getName(), avp);

        if (oldAvp != null) {
          logger.debug("[WARN] Overwrited definition of AVP with the same name: Old: {}, New: {}", new Object[] { oldAvp, avp });
        }
      }
      catch (Exception e) {
        if (logger.isDebugEnabled()) {
          logger.debug(new StringBuffer("[ERROR] Failed Parsing AVP: Name[").append(avpName).append("] Description[").append("N/A").
              append("] Code[").append(avpCode).append("] May-Encrypt[").append(avpMayEncrypt).append("] Mandatory[").append(avpMandatory).
              append("] Protected [").append(avpProtected).append("] Vendor-Bit [").append(avpVendorBit).append("] Vendor-Id [").append(avpVendorId).
              append("] Constrained[").append("N/A").append("] OriginalType [").append(avpOriginalType).
              append("] Type [").append(avpType).append("]").toString(), e);
        }
      }
    }

    for (AvpRepresentation rep : avpMap.values()) {
      markWeaks((AvpRepresentationImpl) rep);
    }
  }
95126
private boolean goToNextDoc() throws IOException {
    if (docId == NO_MORE_DOCS) {
      return true;
    } else {
      // try to find docId with match for all items from sequence
      Integer spanDocId;
      Integer newDocId = null;
      Integer minOptionalDocId = null;
      boolean allItemsOptional = true;
      for (QueueItem item : queueSpans) {
        if (!item.sequenceSpans.optional) {
          allItemsOptional = false;
        }
        if (!item.noMoreDocs) {
          if (item.sequenceSpans.spans == null) {
            spanDocId = NO_MORE_DOCS;
          } else if (newDocId == null) {
            spanDocId = item.sequenceSpans.spans.nextDoc();
          } else {
            if (!item.sequenceSpans.optional) {
              spanDocId = item.sequenceSpans.spans.advance(newDocId);
            } else {
              if (item.sequenceSpans.spans.docID() == -1
                  || newDocId > item.sequenceSpans.spans.docID()) {
                spanDocId = item.sequenceSpans.spans.advance(newDocId);
              } else {
                spanDocId = item.sequenceSpans.spans.docID();
              }
            }
          }
          if (spanDocId.equals(NO_MORE_DOCS)) {
            item.noMoreDocs = true;
            if (!item.sequenceSpans.optional) {
              // a not optional span has NO_MORE_DOCS: stop
              docId = NO_MORE_DOCS;
              return true;
            }
          } else if (!spanDocId.equals(newDocId)) {
            // last found spanDocId not equal to potential new docId
            if (newDocId != null) {
              if (!item.sequenceSpans.optional) {
                // move also previous spans to at least spanDocId
                advance(spanDocId);
                return true;
              }
              // define potential new docId
            } else {
              if (!item.sequenceSpans.optional) {
                // previous optional span with lower docId
                if ((minOptionalDocId != null)
                    && (minOptionalDocId < spanDocId)) {
                  advance(spanDocId);
                  return true;
                } else {
                  // use spanDocId as potential newDocId
                  newDocId = spanDocId;
                }
              } else {
                // remember minimum docId optional spans
                minOptionalDocId = (minOptionalDocId == null) ? spanDocId
                    : Math.min(minOptionalDocId, spanDocId);
              }
            }
          }
        }
      }
      // if all items are optional
      if (allItemsOptional && newDocId == null && minOptionalDocId != null) {
        newDocId = minOptionalDocId;
      }
      // nothing found
      if (newDocId == null) {
        docId = NO_MORE_DOCS;
        return true;
      } else {
        docId = newDocId;
        ignoreItem.advanceToDoc(docId);
        // try and glue together
        if (findMatches()) {
          return true;
          // no matches
        } else {
          resetQueue();
          return false;
        }
      }
    }
  }
1152181
function getVhash() {
  const type = NodeType.VhashType;
  const token = tokens[pos];
  const line = token.ln;
  const column = token.col;

  // Skip `#`.
  pos++;

  const content = getNmName2();
  const end = getLastPosition(content, line, column + 1);
  return newNode(type, content, line, column, end);
}