Пример #1
0
int
createQueueHostSet (struct qData *qp)
{
  int allHosts;
  int i;
  struct hData *hPtr;

  allHosts = qp->numAskedPtr;
  if (allHosts == 0)
    allHosts = numofhosts;

  qp->hostInQueue = setCreate (allHosts,
			       gethIndexByhData,
			       gethDataByhIndex, (char *) __func__);

  if (allHosts == numofhosts)
    {
      for (hPtr = (struct hData *) hostList->back;
	   hPtr != (void *) hostList; hPtr = hPtr->back)
	setAddElement (qp->hostInQueue, hPtr);
    }
  else
    {
      for (i = 0; i < allHosts; i++)
	setAddElement (qp->hostInQueue, qp->askedPtr[i].hData);
    }

  return 0;
}
Пример #2
0
Set setCopy(Set set) {
	IF_NULL_RETURN_NULL(set)
	IS_SET_VALID(set)
	Set newSet = setCreate(set->copyFunc, set->freeFunc, set->cmpFunc);
	IF_NULL_RETURN_NULL(newSet)
	Node nodeToCopy = set->dummy->next;
	Node lastCopiedNode = newSet->dummy;
	newSet->current = NULL; // in case current was undefined in original set
	while (nodeToCopy != NULL) {
		Node currNode = malloc(sizeof(*currNode));
		if (currNode == NULL) {
			setDestroy(newSet);
			return NULL;
		}
		if (nodeToCopy->data == NULL) {
			currNode->data = NULL;
		} else {
			currNode->data = set->copyFunc(nodeToCopy->data);
			if (currNode->data == NULL) {
				free(currNode);
				setDestroy(newSet);
				return NULL;
			}
		}
		if (nodeToCopy == set->current) {
			newSet->current = currNode;
		}
		currNode->next = NULL;
		lastCopiedNode->next = currNode;
		lastCopiedNode = currNode;
		nodeToCopy = nodeToCopy->next;
	}
	newSet->size = setGetSize(set);
	return newSet;
}
Пример #3
0
/**
 * creates cache with special size
 */
Cache cacheCreate(
    int size,
    FreeCacheElement free_element,
    CopyCacheElement copy_element,
    CompareCacheElements compare_elements,
    ComputeCacheKey compute_key) {
	if (size <= 0 || !free_element || !copy_element || !compare_elements || !compute_key) {
		return NULL;
	}
	//memory allocation
	Cache cache;
	CACHE_ALLOCATE(cache_t, cache, NULL);

	//initialization
	cache->computeKey = compute_key;
	cache->cache_size = size;
	cache->iteratorIndex = CACHE_INVALID_ITERATOR_INDEX;
	cache->container = (Set*)malloc(sizeof(*cache->container) * size);
	if (cache->container == NULL) {
		cacheDestroy(cache);
		return NULL;
	}
	CACHE_CONTAINER_FOREACH(i, cache) {
		cache->container[i] = setCreate(copy_element, free_element, compare_elements);
		if (cache->container[i] == NULL) {
			cacheDestroy(cache);
			return NULL;
		}
	}
Пример #4
0
const set *dbCreate(const sds setName)
{
    set *newSet = NULL;

    if (NULL == setName || 0 == strlen(setName))
    {
        return NULL;
    }

    if (NULL == (newSet = setCreate()))
        return NULL;

    lockWrite(sets);

    if (DICT_OK != dictAdd(sets, setName, newSet))
    {
        unlockWrite(sets);
        setDestroy(newSet);
        return NULL;
    }

    if (0 != registerSyncObject(newSet) && 1 != syncObjectIsRegistered(newSet))
    {
        unlockWrite(sets);
        dictDelete(sets, setName);
        setDestroy(newSet);
        return NULL;
    }

    unlockWrite(sets);
    return newSet;
}
void HelloWorld::onData(void* data)
{
    auto goodsdata = (GoodsData*)data;
    if (!goodsdata->isCreate())
    {
        
        if (!_washing)
        {
             _washing = Sprite::create(goodsdata->getResPath());
             addChild(_washing);
        }
        else{
            log("change image");
            _washing->setTexture(goodsdata->getResPath());
            _washing->setVisible(true);
            _washing->setScale(1.0f);
        }
        _washing->setAnchorPoint(Vec2(0.5f,1.618f));
        goodsdata->setCreate(true);
       
    }
    if (scaleAnimation == 1)
    {
        //放小动画
        if (_washing->getScale() > 0.1)
        _washing->setScale(_washing->getScale()-0.03);
    }
}
Пример #6
0
valType dbGC(void)
{
    valType collected = 0, i;
    dictIterator *iter = NULL;
    dictEntry *entry = NULL;
    set *acc = NULL;

    lockWrite(objectIndex);
    lockRead(sets);

    // Step 1. Union all sets in db.
    if (NULL == (iter = dictGetIterator(sets)))
    {
        unlockRead(sets);
        unlockWrite(objectIndex);
        return 0;
    }

    if (NULL == (acc = setCreate()))
    {
        unlockRead(sets);
        unlockWrite(objectIndex);
        return 0;
    }

    while (NULL != (entry = dictNext(iter)))
    {
        valType currentSetId = 0;
        set *tmp = NULL, *currentSet = (set *) dictGetEntryVal(entry);
        set *flattened = setFlatten(currentSet, 0);

        if (NULL == flattened)
        {
            continue;
        }

        if (1 == dbFindSet(currentSet, &currentSetId, 0))
        {
            if (-1 == setAdd(acc, currentSetId))
            {
                setDestroy(acc);
                dictReleaseIterator(iter);
                unlockRead(sets);
                unlockWrite(objectIndex);
                return 0;
            }
        }

        if (NULL == (tmp = setUnion(acc, flattened)))
        {
            setDestroy(flattened);
            setDestroy(acc);
            dictReleaseIterator(iter);
            unlockRead(sets);
            unlockWrite(objectIndex);
            return 0;
        }

        setDestroy(flattened);
        setDestroy(acc);
        acc = tmp;
    }

    dictReleaseIterator(iter);

    // Step 2. Find objects not present in grand total union.
    for (i = 0; i < objectIndexLength; i++)
    {
        if (NULL != objectIndex[i] && !setIsMember(acc, i))
        {
            dbObjectRelease((dbObject *) objectIndex[i]);
            free((dbObject *) objectIndex[i]);
            objectIndex[i] = NULL;

            if (i < objectIndexFreeId)
            {
                objectIndexFreeId = i;
            }

            collected++;
        }
    }

    setDestroy(acc);

    unlockRead(sets);
    unlockWrite(objectIndex);

    return collected;
}
Пример #7
0
/* simpleSetcreate()
 */
LS_BITSET_T *
simpleSetCreate(const int size, char *caller)
{
    return(setCreate(size, NULL, NULL, caller));
}