Пример #1
0
/*
 * The user is expected to initialize hc_host with the address and everything
 * else to the appropriate form of `0'.
 */
int
hc_insert(struct hcentry *hc)
{
	struct hcentry *hc2;
	struct hctable *hct;
	u_long hash;
	int s;

	hct = &hctable[hc->hc_host->sa_family];
	hash = hct->hct_cb->hccb_hash(hc->hc_host, hct->hct_nentries);
	
	hc2 = hct->hct_heads[hash].lh_first;
	for (; hc2; hc2 = hc2->hc_link.le_next) {
		if (cmpsa(hc2->hc_host, hc->hc_host) == 0)
			break;
	}
	if (hc2 != 0)
		return EEXIST;
	hc->hc_hct = hct;
	s = splnet();
	LIST_INSERT_HEAD(&hct->hct_heads[hash], hc, hc_link);
	hct->hct_idle++;
	/*
	 * If the table is now more than 75% full, consider bumping it.
	 */
	if (100 * (hct->hct_idle + hct->hct_active) > 75 * hct->hct_nentries)
		maybe_bump_hash(hct);
	splx(s);
	return 0;
}
Пример #2
0
struct hcentry *
hc_get(struct sockaddr *sa)
{
	u_long hash;
	struct hcentry *hc;
	struct hctable *hct;
	int s;

	hct = &hctable[sa->sa_family];
	if (hct->hct_nentries == 0)
		return 0;
	hash = hct->hct_cb->hccb_hash(sa, hct->hct_nentries);
	hc = hct->hct_heads[hash].lh_first;
	for (; hc; hc = hc->hc_link.le_next) {
		if (cmpsa(hc->hc_host, sa) == 0)
			break;
	}
	if (hc == 0)
		return 0;
	s = splnet();
	if (hc->hc_rt && (hc->hc_rt->rt_flags & RTF_UP) == 0) {
		RTFREE(hc->hc_rt);
		hc->hc_rt = 0;
	}
	if (hc->hc_rt == 0) {
		hc->hc_rt = rtalloc1(hc->hc_host, 1, 0);
	}
	hc_ref(hc);
	splx(s);
	/* XXX move to front of list? */
	return hc;
}
Пример #3
0
void suffix(int n,int m = 128) {
    int i;
    for(i = 0; i < n; i++) r[i] = a[i], sa[i] = i;
    for(len = 1; len < n; len <<=1) {
        std::sort(sa,sa+n,cmpsa);
        Rank[sa[0]] = 0;
        int tot = 1;
        for(i = 1; i < n; i++)
            Rank[sa[i]] = cmpsa(sa[i-1],sa[i]) ? tot++ : tot-1;
        for(i = 0; i < n; i++) r[i] = Rank[i];
        if(tot == n) break;
    }
    calh(n-1);
}