xref: /netbsd-src/usr.bin/m4/lib/ohash_interval.c (revision 71dafaa1f2404e3d305953a2adb9753e60d418ae)
1*71dafaa1Schristos /* $OpenBSD: ohash_interval.c,v 1.3 2006/01/16 15:52:25 espie Exp $ */
2*71dafaa1Schristos /* ex:ts=8 sw=4:
3*71dafaa1Schristos  */
4*71dafaa1Schristos 
5*71dafaa1Schristos /* Copyright (c) 1999, 2004 Marc Espie <espie@openbsd.org>
6*71dafaa1Schristos  *
7*71dafaa1Schristos  * Permission to use, copy, modify, and distribute this software for any
8*71dafaa1Schristos  * purpose with or without fee is hereby granted, provided that the above
9*71dafaa1Schristos  * copyright notice and this permission notice appear in all copies.
10*71dafaa1Schristos  *
11*71dafaa1Schristos  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12*71dafaa1Schristos  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13*71dafaa1Schristos  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14*71dafaa1Schristos  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15*71dafaa1Schristos  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16*71dafaa1Schristos  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17*71dafaa1Schristos  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18*71dafaa1Schristos  */
19*71dafaa1Schristos 
20*71dafaa1Schristos #include "ohash_int.h"
21*71dafaa1Schristos 
22*71dafaa1Schristos uint32_t
ohash_interval(const char * s,const char ** e)23*71dafaa1Schristos ohash_interval(const char *s, const char **e)
24*71dafaa1Schristos {
25*71dafaa1Schristos 	uint32_t k;
26*71dafaa1Schristos 
27*71dafaa1Schristos 	if (!*e)
28*71dafaa1Schristos 		*e = s + strlen(s);
29*71dafaa1Schristos 	if (s == *e)
30*71dafaa1Schristos 		k = 0;
31*71dafaa1Schristos 	else
32*71dafaa1Schristos 		k = *s++;
33*71dafaa1Schristos 	while (s != *e)
34*71dafaa1Schristos 		k =  ((k << 2) | (k >> 30)) ^ *s++;
35*71dafaa1Schristos 	return k;
36*71dafaa1Schristos }
37