#if defined(__cplusplus)
extern "C" {
#endif

#ifndef MYSTRING_H
#define MYSTRING_H


typedef unsigned long ulong;

inline long StrCmp4(const char* a,const char* b)
// Fast comparator for words of minimum length 4
{
	const ulong* wa=(ulong*)(a);	
	const ulong* wb=(ulong*)(b);
	ulong ca=*wa;
	ulong cb=*wb;
	long d=ca-cb;
	if (d) return d;
 	a+=3,b+=3;
	do// (;;)
	{
		ca=*++a;
		cb=*++b;		
		d=ca-cb;		
		//if (d) break;// words differ
		//if (ca==0) break;// words same, and NULL reached
	} while (ca && (d==0));
	return d;
}

inline long StrCmpN4(const char* a,const char* b,ulong n)
// Fast comparator for words of minimum length 4, up to n letters
{
	const ulong* wa=(ulong*)(a);	
	const ulong* wb=(ulong*)(b);
	ulong ca=*wa;
	ulong cb=*wb;
	long d=ca-cb;
	if (d) return d;
 	a+=3,b+=3;
	for (int i=4;i<n;i++)
	{
		ca=*++a;
		cb=*++b;		
		d=ca-cb;		
		if (d) break;// words differ
		if (ca==0) break;// words same, and NULL reached
	}
	return d;
}

inline ulong StrLen4(const char* w)
{
	ulong len=4;
	w+=3;
	while (*++w) len++;
	return len;
}


#endif

#if defined(__cplusplus)
}
#endif
