Пример #1
0
TTErr TTHash::getKeysSorted(TTValue& hashKeysSorted, TTBoolean(comparisonFunction)(TTValue&, TTValue&))
{
	lock();
	TTList		listToSort;
	TTValue		v;
	TTSymbol	key;
	
	// fill a list to sort
	for (TTHashMapIter iter = HASHMAP->begin(); iter != HASHMAP->end(); iter++) {
		TTPtrSizedInt	a = iter->first;
		TTSymbol		b((TTSymbolBase*)a);
		
		if (comparisonFunction) {
			v = b;	// the key
			v.append(TTPtr(iter->second));	// a pointer to the stored value
			listToSort.append(v);
		}
		else
			listToSort.append(b);
	}
	
	listToSort.sort(comparisonFunction);
	
	// fill the result
	hashKeysSorted.clear();
	for (listToSort.begin(); listToSort.end(); listToSort.next()) {
		
		if (comparisonFunction) {
			key = listToSort.current()[0];
			hashKeysSorted.append(key);
		}
		else
			hashKeysSorted.append(listToSort.current());
	}
	
	unlock();
	return kTTErrNone;
}