/*
 * Copyright 2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.kuujo.copycat.io.util;

import net.kuujo.copycat.util.internal.Buffers;

import java.nio.ByteBuffer;

/**
 * Hash function.
 *
 * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
 */
public interface HashFunction {

  /**
   * Converts a 64-bit hash value into a 32-bit hash.
   *
   * @param hash The hash value to convert.
   * @return The converted hash value.
   */
  static int asInt(long hash) {
    return (int) (hash - (hash >> 32)) & (2^32 - 1);
  }

  /**
   * Creates a 32-bit hash of the given bytes.
   *
   * @param bytes The bytes to hash.
   * @return The hash value.
   */
  default int asInt(byte[] bytes) {
    long hash = hashBytes(bytes);
    return asInt(hash);
  }

  /**
   * Hashes the remaining bytes in the given buffer.
   *
   * @param buffer The buffer to hash.
   * @return The hashed buffer bytes.
   */
  default long hashBytes(ByteBuffer buffer) {
    return hashBytes(Buffers.getBytes(buffer));
  }

  /**
   * Hashes the given bytes.
   *
   * @param bytes The bytes to hash.
   * @return The hashed bytes.
   */
  long hashBytes(byte[] bytes);

}

@@ -640,16 +640,87 @@
 .util;%0A%0A
+import net.kuujo.copycat.io.Buffer;%0Aimport net.kuujo.copycat.io.Bytes;%0A
 import n
@@ -1628,32 +1628,614 @@
 (buffer));%0A  %7D%0A%0A
+  /**%0A   * Hashes the remaining bytes in the given buffer.%0A   *%0A   * @param buffer The buffer to hash.%0A   * @return The hashed buffer bytes.%0A   */%0A  default long hashBytes(Buffer buffer) %7B%0A    byte%5B%5D bytes = new byte%5B(int) buffer.remaining()%5D;%0A    buffer.read(bytes);%0A    return hashBytes(bytes);%0A  %7D%0A%0A  /**%0A   * Hashes the given bytes.%0A   *%0A   * @param bytes The bytes to hash.%0A   * @return The hashed bytes.%0A   */%0A  default long hashBytes(Bytes bytes) %7B%0A    byte%5B%5D barray = new byte%5B(int) bytes.size()%5D;%0A    bytes.read(barray, 0, bytes.size());%0A    return hashBytes(barray);%0A  %7D%0A%0A
   /**%0A   * Hashe

Add default hash methods for Bytes and Buffer.