add find()
git-svn-id: http://skia.googlecode.com/svn/trunk@1243 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
2dbd0449bf
commit
8d90eeba09
@ -28,6 +28,12 @@
|
|||||||
*/
|
*/
|
||||||
class SkPtrSet : public SkRefCnt {
|
class SkPtrSet : public SkRefCnt {
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* Search for the specified ptr in the set. If it is found, return its
|
||||||
|
* 32bit ID [1..N], or if not found, return 0. Always returns 0 for NULL.
|
||||||
|
*/
|
||||||
|
uint32_t find(void*) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the specified ptr to the set, returning a unique 32bit ID for it
|
* Add the specified ptr to the set, returning a unique 32bit ID for it
|
||||||
* [1...N]. Duplicate ptrs will return the same ID.
|
* [1...N]. Duplicate ptrs will return the same ID.
|
||||||
|
@ -15,6 +15,22 @@ int SkPtrSet::Cmp(const Pair& a, const Pair& b) {
|
|||||||
return (char*)a.fPtr - (char*)b.fPtr;
|
return (char*)a.fPtr - (char*)b.fPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t SkPtrSet::find(void* ptr) const {
|
||||||
|
if (NULL == ptr) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = fList.count();
|
||||||
|
Pair pair;
|
||||||
|
pair.fPtr = ptr;
|
||||||
|
|
||||||
|
int index = SkTSearch<Pair>(fList.begin(), count, pair, sizeof(pair), &Cmp);
|
||||||
|
if (index < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return fList[index].fIndex;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t SkPtrSet::add(void* ptr) {
|
uint32_t SkPtrSet::add(void* ptr) {
|
||||||
if (NULL == ptr) {
|
if (NULL == ptr) {
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user