亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? cpspacehash.c

?? Compressed file has password
?? C
字號:
/* Copyright (c) 2007 Scott Lembcke *  * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: *  * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. *  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #include <stdlib.h>#include <stdio.h>#include <math.h>#include <assert.h>#include "chipmunk.h"#include "prime.h"static cpHandle*cpHandleAlloc(void){	return (cpHandle *)malloc(sizeof(cpHandle));}static cpHandle*cpHandleInit(cpHandle *hand, void *obj){	hand->obj = obj;	hand->retain = 0;	hand->stamp = 0;		return hand;}static cpHandle*cpHandleNew(void *obj){	return cpHandleInit(cpHandleAlloc(), obj);}static inline voidcpHandleRetain(cpHandle *hand){	hand->retain++;}static inline voidcpHandleFree(cpHandle *hand){	free(hand);}static inline voidcpHandleRelease(cpHandle *hand){	hand->retain--;	if(hand->retain == 0)		cpHandleFree(hand);}cpSpaceHash*cpSpaceHashAlloc(void){	return (cpSpaceHash *)calloc(1, sizeof(cpSpaceHash));}// Frees the old table, and allocates a new one.static voidcpSpaceHashAllocTable(cpSpaceHash *hash, int numcells){	free(hash->table);		hash->numcells = numcells;	hash->table = (cpSpaceHashBin **)calloc(numcells, sizeof(cpSpaceHashBin *));}// Equality function for the handleset.static inthandleSetEql(void *obj, void *elt){	cpHandle *hand = (cpHandle *)elt;	return (obj == hand->obj);}// Transformation function for the handleset.static void *handleSetTrans(void *obj, void *unused){	cpHandle *hand = cpHandleNew(obj);	cpHandleRetain(hand);		return hand;}cpSpaceHash*cpSpaceHashInit(cpSpaceHash *hash, cpFloat celldim, int numcells, cpSpaceHashBBFunc bbfunc){	cpSpaceHashAllocTable(hash, next_prime(numcells));	hash->celldim = celldim;	hash->bbfunc = bbfunc;		hash->bins = NULL;	hash->handleSet = cpHashSetNew(0, &handleSetEql, &handleSetTrans);		hash->stamp = 1;		return hash;}cpSpaceHash*cpSpaceHashNew(cpFloat celldim, int cells, cpSpaceHashBBFunc bbfunc){	return cpSpaceHashInit(cpSpaceHashAlloc(), celldim, cells, bbfunc);}static inline voidclearHashCell(cpSpaceHash *hash, int index){	cpSpaceHashBin *bin = hash->table[index];	while(bin){		cpSpaceHashBin *next = bin->next;				// Release the lock on the handle.		cpHandleRelease(bin->handle);		// Recycle the bin.		bin->next = hash->bins;		hash->bins = bin;				bin = next;	}		hash->table[index] = NULL;}// Clear all cells in the hashtable.static voidclearHash(cpSpaceHash *hash){	for(int i=0; i<hash->numcells; i++)		clearHashCell(hash, i);}// Free the recycled hash bins.static voidfreeBins(cpSpaceHash *hash){	cpSpaceHashBin *bin = hash->bins;	while(bin){		cpSpaceHashBin *next = bin->next;		free(bin);		bin = next;	}}// Hashset iterator function to free the handles.static voidhandleFreeWrap(void *elt, void *unused){	cpHandle *hand = (cpHandle *)elt;	cpHandleFree(hand);}voidcpSpaceHashDestroy(cpSpaceHash *hash){	clearHash(hash);	freeBins(hash);		// Free the handles.	cpHashSetEach(hash->handleSet, &handleFreeWrap, NULL);	cpHashSetFree(hash->handleSet);		free(hash->table);}voidcpSpaceHashFree(cpSpaceHash *hash){	if(!hash) return;	cpSpaceHashDestroy(hash);	free(hash);}voidcpSpaceHashResize(cpSpaceHash *hash, cpFloat celldim, int numcells){	// Clear the hash to release the old handle locks.	clearHash(hash);		hash->celldim = celldim;	cpSpaceHashAllocTable(hash, next_prime(numcells));}// Return true if the chain contains the handle.static inline intcontainsHandle(cpSpaceHashBin *bin, cpHandle *hand){	while(bin){		if(bin->handle == hand) return 1;		bin = bin->next;	}		return 0;}// Get a recycled or new bin.static inline cpSpaceHashBin *getEmptyBin(cpSpaceHash *hash){	cpSpaceHashBin *bin = hash->bins;		// Make a new one if necessary.	if(bin == NULL) return (cpSpaceHashBin *)malloc(sizeof(cpSpaceHashBin));	hash->bins = bin->next;	return bin;}// The hash function itself.static inline unsigned inthash_func(unsigned int x, unsigned int y, unsigned int n){	return (x*2185031351ul ^ y*4232417593ul) % n;}static inline voidhashHandle(cpSpaceHash *hash, cpHandle *hand, cpBB bb){	// Find the dimensions in cell coordinates.	cpFloat dim = hash->celldim;	int l = bb.l/dim;	int r = bb.r/dim;	int b = bb.b/dim;	int t = bb.t/dim;		int n = hash->numcells;	for(int i=l; i<=r; i++){		for(int j=b; j<=t; j++){			int index = hash_func(i,j,n);			cpSpaceHashBin *bin = hash->table[index];						// Don't add an object twice to the same cell.			if(containsHandle(bin, hand)) continue;			cpHandleRetain(hand);			// Insert a new bin for the handle in this cell.			cpSpaceHashBin *newBin = getEmptyBin(hash);			newBin->handle = hand;			newBin->next = bin;			hash->table[index] = newBin;		}	}}voidcpSpaceHashInsert(cpSpaceHash *hash, void *obj, unsigned int id, cpBB bb){	cpHandle *hand = (cpHandle *)cpHashSetInsert(hash->handleSet, id, obj, NULL);	hashHandle(hash, hand, bb);}voidcpSpaceHashRehashObject(cpSpaceHash *hash, void *obj, unsigned int id){	cpHandle *hand = (cpHandle *)cpHashSetFind(hash->handleSet, id, obj);	hashHandle(hash, hand, hash->bbfunc(obj));}// Hashset iterator function for rehashing the spatial hash. (hash hash hash hash?)static voidhandleRehashHelper(void *elt, void *data){	cpHandle *hand = (cpHandle *)elt;	cpSpaceHash *hash = (cpSpaceHash *)data;		hashHandle(hash, hand, hash->bbfunc(hand->obj));}voidcpSpaceHashRehash(cpSpaceHash *hash){	clearHash(hash);		// Rehash all of the handles.	cpHashSetEach(hash->handleSet, &handleRehashHelper, hash);}voidcpSpaceHashRemove(cpSpaceHash *hash, void *obj, unsigned int id){	cpHandle *hand = (cpHandle *)cpHashSetRemove(hash->handleSet, id, obj);		if(hand){		hand->obj = NULL;		cpHandleRelease(hand);	}}// Used by the cpSpaceHashEach() iterator.typedef struct eachPair {	cpSpaceHashIterator func;	void *data;} eachPair;// Calls the user iterator function. (Gross I know.)static voideachHelper(void *elt, void *data){	cpHandle *hand = (cpHandle *)elt;	eachPair *pair = (eachPair *)data;		pair->func(hand->obj, pair->data);}// Iterate over the objects in the spatial hash.voidcpSpaceHashEach(cpSpaceHash *hash, cpSpaceHashIterator func, void *data){	// Bundle the callback up to send to the hashset iterator.	eachPair pair = {func, data};		cpHashSetEach(hash->handleSet, &eachHelper, &pair);}// Calls the callback function for the objects in a given chain.static inline voidquery(cpSpaceHash *hash, cpSpaceHashBin *bin, void *obj, cpSpaceHashQueryFunc func, void *data){	for(; bin; bin = bin->next){		cpHandle *hand = bin->handle;		void *other = hand->obj;				// Skip over certain conditions		if(			// Have we already tried this pair in this query?			hand->stamp == hash->stamp			// Is obj the same as other?			|| obj == other 			// Has other been removed since the last rehash?			|| !other			) continue;				func(obj, other, data);		// Stamp that the handle was checked already against this object.		hand->stamp = hash->stamp;	}}voidcpSpaceHashPointQuery(cpSpaceHash *hash, cpVect point, cpSpaceHashQueryFunc func, void *data){	cpFloat dim = hash->celldim;	int index = hash_func((int)(point.x/dim), (int)(point.y/dim), hash->numcells);		query(hash, hash->table[index], &point, func, data);	// Increment the stamp.	// Only one cell is checked, but query() requires it anyway.	hash->stamp++;}voidcpSpaceHashQuery(cpSpaceHash *hash, void *obj, cpBB bb, cpSpaceHashQueryFunc func, void *data){	// Get the dimensions in cell coordinates.	cpFloat dim = hash->celldim;	int l = bb.l/dim;	int r = bb.r/dim;	int b = bb.b/dim;	int t = bb.t/dim;		int n = hash->numcells;		// Iterate over the cells and query them.	for(int i=l; i<=r; i++){		for(int j=b; j<=t; j++){			int index = hash_func(i,j,n);			query(hash, hash->table[index], obj, func, data);		}	}		// Increment the stamp.	hash->stamp++;}// Similar to struct eachPair above.typedef struct queryRehashPair {	cpSpaceHash *hash;	cpSpaceHashQueryFunc func;	void *data;} queryRehashPair;// Hashset iterator func used with cpSpaceHashQueryRehash().static voidhandleQueryRehashHelper(void *elt, void *data){	cpHandle *hand = (cpHandle *)elt;		// Unpack the user callback data.	queryRehashPair *pair = (queryRehashPair *)data;	cpSpaceHash *hash = pair->hash;	cpSpaceHashQueryFunc func = pair->func;	cpFloat dim = hash->celldim;	int n = hash->numcells;	void *obj = hand->obj;	cpBB bb = hash->bbfunc(obj);	int l = bb.l/dim;	int r = bb.r/dim;	int b = bb.b/dim;	int t = bb.t/dim;	for(int i=l; i<=r; i++){		for(int j=b; j<=t; j++){			int index = hash_func(i,j,n);			cpSpaceHashBin *bin = hash->table[index];						if(containsHandle(bin, hand)) continue;			query(hash, bin, obj, func, pair->data);						cpHandleRetain(hand);			cpSpaceHashBin *newBin = getEmptyBin(hash);			newBin->handle = hand;			newBin->next = bin;			hash->table[index] = newBin;		}	}		// Increment the stamp for each object we hash.	hash->stamp++;}voidcpSpaceHashQueryRehash(cpSpaceHash *hash, cpSpaceHashQueryFunc func, void *data){	clearHash(hash);	queryRehashPair pair = {hash, func, data};	cpHashSetEach(hash->handleSet, &handleQueryRehashHelper, &pair);}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99热这里都是精品| 国产精品国产精品国产专区不蜜| 91福利视频久久久久| 成人黄色在线看| 成人小视频免费在线观看| 国产一区高清在线| 狠狠色狠狠色综合日日91app| 欧美a级一区二区| 麻豆精品一区二区综合av| 热久久久久久久| 国产综合色产在线精品| 国产真实精品久久二三区| 国内精品自线一区二区三区视频| 久久草av在线| 国产福利一区二区| 99精品视频在线免费观看| 色呦呦日韩精品| 欧美日韩视频在线观看一区二区三区 | 99国产精品99久久久久久| 国产成人精品一区二区三区网站观看| 国产91精品免费| 91成人免费网站| 678五月天丁香亚洲综合网| 亚洲欧洲无码一区二区三区| 亚洲美女一区二区三区| 亚洲综合在线观看视频| 天天av天天翘天天综合网色鬼国产| 日日骚欧美日韩| 狠狠色狠狠色综合| 成人激情黄色小说| 欧美日韩午夜在线视频| 亚洲精品一线二线三线| 中文字幕成人av| 一区二区三区四区精品在线视频| 日韩在线一区二区三区| 国产在线精品一区二区夜色 | 亚洲精品在线一区二区| 国产午夜亚洲精品羞羞网站| 综合欧美一区二区三区| 午夜精品视频在线观看| 国内外精品视频| 欧美视频中文字幕| 亚洲精品一区二区三区四区高清 | 麻豆成人免费电影| 春色校园综合激情亚洲| 欧美日韩美女一区二区| 国产亚洲精久久久久久| 夜色激情一区二区| 国产一区二区美女| 在线观看视频一区| 久久综合狠狠综合| 亚洲一二三区在线观看| 国产一区91精品张津瑜| 欧美性大战久久久久久久| 久久久久国产精品免费免费搜索| 一区二区三区在线播放| 黄色日韩三级电影| 在线观看视频一区二区欧美日韩| 久久综合九色综合欧美就去吻 | 欧洲精品在线观看| 精品成人私密视频| 精品国产一区二区在线观看| 亚洲品质自拍视频网站| 国产一区二区三区四区在线观看| 色婷婷精品大视频在线蜜桃视频| 欧美大片一区二区三区| 伊人开心综合网| 春色校园综合激情亚洲| 欧美videos大乳护士334| 亚洲综合网站在线观看| 国产91丝袜在线播放0| 欧美一级理论片| 一区二区三国产精华液| 国产成人av福利| 欧美精品vⅰdeose4hd| 欧美国产在线观看| 久久91精品久久久久久秒播| 色激情天天射综合网| 国产亚洲欧美在线| 久久se精品一区二区| 在线精品视频一区二区| 亚洲人123区| 成人福利视频在线| 久久久久久毛片| 奇米影视7777精品一区二区| 欧美日韩国产免费一区二区| 亚洲在线观看免费视频| 97久久精品人人做人人爽50路| 国产亚洲女人久久久久毛片| 免费在线看一区| 宅男噜噜噜66一区二区66| 亚洲一区二区三区中文字幕在线| 91伊人久久大香线蕉| 国产精品美女视频| 成人免费三级在线| 欧美激情一区二区三区全黄| 精东粉嫩av免费一区二区三区| 日韩欧美aaaaaa| 精品亚洲免费视频| 欧美一区2区视频在线观看| 视频一区中文字幕| 制服丝袜亚洲播放| 日韩中文欧美在线| 日韩午夜精品视频| 日本人妖一区二区| 日韩一区国产二区欧美三区| 蜜臀久久久久久久| 欧美一级片在线看| 久久精品久久综合| www国产精品av| 国产99久久久精品| 国产精品网站在线观看| aa级大片欧美| 洋洋av久久久久久久一区| 欧洲国内综合视频| 日韩国产精品久久久久久亚洲| 91精品黄色片免费大全| 老司机免费视频一区二区| 久久综合久久99| 成人性生交大片| 亚洲靠逼com| 欧美日本国产视频| 久久精品国产亚洲高清剧情介绍| 日韩欧美不卡在线观看视频| 国产乱人伦偷精品视频不卡 | 国产一区在线精品| 国产午夜精品久久久久久久| 成人高清免费在线播放| 一区二区免费看| 在线不卡欧美精品一区二区三区| 蜜臀久久99精品久久久久宅男| 精品成人佐山爱一区二区| 高清免费成人av| 最近日韩中文字幕| 欧美日韩一区小说| 韩国女主播成人在线| 国产精品国产三级国产有无不卡 | 久久99精品国产| 中文av一区特黄| 在线观看日韩高清av| 青青草伊人久久| 国产精品国产三级国产aⅴ中文| 在线观看亚洲a| 国产一区二区三区精品欧美日韩一区二区三区 | 亚洲午夜精品久久久久久久久| 日韩色在线观看| 99精品国产99久久久久久白柏| 亚洲一区二区综合| 欧美精品一区二区三区蜜桃| 91视频在线观看免费| 日韩avvvv在线播放| 欧美国产乱子伦| 欧美一级二级三级乱码| 成人av网站在线观看免费| 午夜伦欧美伦电影理论片| 中文在线资源观看网站视频免费不卡 | 三级亚洲高清视频| 久久久精品免费观看| 欧美中文字幕不卡| 成人亚洲一区二区一| 日韩国产精品91| 欧美高清在线精品一区| 欧美一区二区三区视频免费播放| va亚洲va日韩不卡在线观看| 琪琪久久久久日韩精品| 亚洲精品精品亚洲| 久久精品人人做| 欧美一区二区久久| 色呦呦一区二区三区| 成人免费视频视频| 久久99国产精品久久99| 日韩精品亚洲一区二区三区免费| 国产精品女同一区二区三区| 日韩欧美一区二区久久婷婷| 91国偷自产一区二区三区成为亚洲经典 | 激情五月播播久久久精品| 亚洲第一搞黄网站| 亚洲欧洲精品一区二区精品久久久| 日韩一区二区三区电影| 欧美三级中文字| 99精品在线观看视频| 国产一区二区日韩精品| 麻豆精品在线播放| 日韩不卡免费视频| 亚洲成a天堂v人片| 亚洲色图自拍偷拍美腿丝袜制服诱惑麻豆| 欧美第一区第二区| 日韩一二三区不卡| 欧美日韩国产高清一区二区三区| av激情综合网| 成人激情黄色小说| 国产不卡在线播放| 韩日av一区二区| 久久成人麻豆午夜电影| 日韩高清中文字幕一区| 午夜视频在线观看一区| 亚洲国产精品欧美一二99| 一区二区三区四区不卡视频| 一区二区三区影院| 一区二区三区 在线观看视频|