static int changeSameKey (char *key, ArrayHashTable2 *hashTable, ArrayHashTableElement2 *element) { unsigned int pos=generatePosition(key, hashTable->size); ArrayHashTableElement2 *try=hashTable->hashArray[pos]; if (try==NULL) return -1; int newIndex=solveConflict(pos, key, hashTable); if (newIndex==-1) return -1; free(hashTable->hashArray[newIndex]); hashTable->hashArray[newIndex]=element; return 1; }
// Calculate the mapping order and mapping score void S2MP::calcMappingScore() { _mappingOrder.clearQuick(); // keep track of the number of matching weights equal to zero int coutnMinusOnes = 0; // find the position of each row's max matching weight for (int i = 0; i < (_sp1len - _sp1frst); i++) { // in the case of two matching Max weights, we take the first one int weightPos = indexOfMax(_w.getReference(i)); // set all mappings associated with a meanininglessly small weight to -1 if (_w.getReference(i).getUnchecked(weightPos) < 0.00001) { weightPos = -1; coutnMinusOnes += 1; } // store matching weight position i.e. max weight in this row _mappingOrder.add(weightPos); } // If there are no mappings, return with mappingScore = 0 if (coutnMinusOnes == _mappingOrder.size()) { _mappingScore = 0; return; } // Now detect conflicts/duplicates (two itemsets in sp1 mapped to the same itemset in sp2) for (int i = 0; i < (_sp1len - _sp1frst - 1); i++) { //if we have a none zero matching weight, find conflict and resolve if (_mappingOrder.getUnchecked(i) > -1) { for (int k = i + 1; k < (_sp1len - _sp1frst); k++) { if (_mappingOrder.getUnchecked(i) == _mappingOrder.getUnchecked(k)) solveConflict(i, k); } } } // set _mapping_score to the mean of the weights of the mapped itemsets and return double count = 0.0; double total = 0.0; for (int i = 0; i < _mappingOrder.size(); i++) { if (_mappingOrder.getUnchecked(i) > -1) { total += _w.getReference(i)[_mappingOrder.getUnchecked(i)]; count += 1.0; } } if (count != 0) { _mappingScore = total/count; } else { _mappingScore = 0.0; } }