⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 string.c

📁 window下的c编译器。
💻 C
字号:
#include "c.h"

static struct string {
	char *str;
	int len;
	struct string *link;
} *buckets[1024];
static unsigned scatter[] = { /* Map characters to random values */
 	3376649973u, 2288603946u, 1954268477u, 2858154129u, 3254987376u,
 	1888560329u, 2079711150u, 1249903931u, 2056019508u, 3475721719u,
 	2183608578u, 1948585191u, 3510366957u,  479341015u,  137912281u,
 	1856397162u,  701025146u, 3777855647u, 3133726730u, 4113368641u,
 	 251772918u, 2859869442u,  824540103u,  614317204u, 3085688794u,
 	1104489690u, 3600905459u, 1036657084u, 1960148944u, 2441465117u,
 	3633092952u, 1202079507u, 1804386472u, 3798190281u, 2511419699u,
 	1032473403u, 3235883220u, 2593233477u, 2484192352u, 1834174643u,
 	3630460796u, 3436981729u,  876656665u, 1144446061u, 2179315054u,
 	2142937421u, 1163901871u,  703364539u, 1635510196u, 1558480853u,
 	3800782692u,  604753589u, 3558571372u,  274373881u,  183696063u,
 	4013401969u, 3787387983u,  551169993u, 2706792174u,  475596077u,
 	 784566245u, 2043924368u, 1567342084u, 3331009165u,  150886268u,
 	 596437426u, 2420547845u, 2898343441u, 1643521607u, 1387052253u,
 	 691524517u, 1709282085u, 2105726706u,  326318904u, 2270893751u,
 	1547094850u,  273913063u, 1180303327u, 1015098316u, 1122706416u,
 	1025137522u, 1445737386u, 3992079916u, 3230843455u, 3002906788u,
 	3543652723u, 1755107124u, 1921014418u,  683842306u, 2503306554u,
 	3688139822u, 3812611237u, 3363198012u, 1643682998u,  285631714u,
 	1910683492u, 4281003621u, 3709237568u, 2736065042u, 1422760317u,
 	 862182498u, 2248178396u, 3197393735u, 3974531276u,  157092128u,
 	3859796014u,  851355354u, 2511336234u, 3700246600u,  572627716u,
 	1519995253u,  342913937u,  328362706u, 3497158594u,  739312110u,
 	1482159142u, 4059308452u, 1115275813u, 2279798033u, 3563459711u,
 	 102382981u,  698626900u, 2506327534u, 2223405777u, 1827275406u,
 	 159038005u, 4159863896u, 3470995235u,  130302168u, 1077990744u,
 	1441602901u, 2757433577u,  200115595u,  993264331u, 2598999266u,
 	3842878136u, 3530540372u, 1361428823u,  248277624u, 1339695154u,
 	 432480863u, 2895143187u, 3166708344u, 2393286685u, 4271569970u,
 	 869342786u,  473223354u,  126812611u, 3904940903u, 1637555894u,
 	 996061127u, 1088298011u, 2952176066u, 2858912209u, 4228613491u,
 	4236158822u, 2582423590u, 2525024672u, 3677112391u, 3629698756u,
 	1496034522u, 2081171139u, 2352170546u,  176561938u, 3553901024u,
 	1142683711u, 2409311685u,  672560988u, 3693784086u,  689665476u,
 	1992869305u, 2102947696u, 1890679203u, 2387696458u, 1988263978u,
 	1536664131u,  768867302u, 2456175399u, 3136223828u,  202652382u,
 	4142812934u,  245277491u, 2630667112u,  240720193u, 2395371056u,
 	 707955862u, 4095017737u, 3236774548u, 3681653056u, 3285235880u,
 	 807411619u,  721125152u, 2671591148u, 4255706610u, 1694083953u,
 	3615121285u, 2744541524u, 2146568054u,  432941567u, 1070843254u,
 	2173029527u, 3630977578u, 3297023538u,   77429635u, 4131306785u,
 	1890732898u, 2010001485u, 1144304337u, 1673699809u, 1335369816u,
 	3596270401u, 3614930280u,  170584627u,  190006287u, 1491467787u,
 	 821380901u,  196708749u,  986375533u, 3133295550u, 2991205574u,
 	3983654535u, 3338932148u, 2374084740u, 4292366978u, 3657247497u,
 	3856158535u, 1497347358u, 3204988225u, 2733738804u, 1120807021u,
 	 450893717u, 2518878143u,   55245244u,  435713941u,  688959256u,
 	3878081060u, 3828717777u, 2111290183u, 3684667667u,  147090689u,
 	 671188737u, 1379556449u, 1326383789u, 1628432838u,  462410620u,
 	 544713991u, 1591539421u, 2938270133u, 1902128118u,  560215823u,
 	4293430683u, 1041753686u, 1365246147u, 2681506285u,  500008709u,
 	1129892475u
};
char *string(char *str)
{
	char *s;

	for (s = str; *s; s++)
		;
	return stringn(str, s - str);
}
char *stringd(int n)
{
	char str[25], *s = str + sizeof (str);
	unsigned m;

	if (n == INT_MIN)
		m = (unsigned)INT_MAX + 1;
	else if (n < 0)
		m = -n;
	else
		m = n;
	do
		*--s = (char)(m%10 + '0');
	while ((m /= 10) != 0);
	if (n < 0)
		*--s = '-';
	return stringn(s, str + sizeof (str) - s);
}
char *stringn(char *str,int len)
{
	int i;
	unsigned int h;
	char *end;
	struct string *p;

	assert(str);
	for (h = 0, i = len, end = str; i > 0; i--)
		h = (h>>1) ^ scatter[*(unsigned char *)end++];
	h &= NELEMS(buckets)-1;
	i = *str;
	for (p = buckets[h]; p; p = p->link)
		if (len == p->len &&
			(char)i == *p->str &&
			!memcmp(str,p->str,len)) {
			return p->str;
		}
	{
		static char *next, *strlimit;
		if (next + len + 1 >= strlimit) {
			int n = len + 4*1024;
			next = allocate(n, PERM);
			strlimit = next + n;
		}
		NEW(p, PERM);
		p->len = len;
		p->str = next;
		memcpy(next,str,len);
		next += len;
		*next++ = 0;
		p->link = buckets[h];
		buckets[h] = p;
		return p->str;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -