All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fuzzydb.util.Adler64 Maven / Gradle / Ivy

Go to download

Contains classes not specific to fuzzydb implementation which could be used in any implementation of fuzzy matching, or as general utility classes such as those in the geo package.

The newest version!
/******************************************************************************
 * Copyright (c) 2004-2008 Whirlwind Match Limited. All rights reserved.
 *
 * This is open source software; you can use, redistribute and/or modify
 * it under the terms of the Open Software Licence v 3.0 as published by the 
 * Open Source Initiative.
 *
 * You should have received a copy of the Open Software Licence along with this
 * application. if not, contact the Open Source Initiative (www.opensource.org)
 *****************************************************************************/
package org.fuzzydb.util;

import java.util.zip.Checksum;

/**This is a home-rolled version of the Adler32 checksum algo.
 * It has been expanded for 64 bit operation using the same rules.
 * This is not guaranteed to be the same algo as some other Adler64.
 */
public final class Adler64 implements Checksum {

	private long s1;	// These are used as unsigned 32 bit
	private long s2;
	
	private final static long crcBase = 4294967291l;	// prime less than 2^32
	
	public Adler64() {
		super();
		reset();
	}
	
	@Override
	public final void update(int b) {
		s1 += b;
		if (s1>=crcBase)
		 {
			s1 -= crcBase;	// same as mod % but with no risk of costly 64 bit math
		}
		s2 += s1;
		if (s2>=crcBase) {
			s2 -= crcBase;
		}
	}

	@Override
	public final void update(byte[] b, int off, int len) {
		for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy