| 258 | } |
| 259 | |
| 260 | static void |
| 261 | node_hash_update(GHashTable * list1, GHashTable * list2, const char *attr, float factor, |
| 262 | gboolean only_positive) |
| 263 | { |
| 264 | int score = 0; |
| 265 | int new_score = 0; |
| 266 | GHashTableIter iter; |
| 267 | node_t *node = NULL; |
| 268 | |
| 269 | if (attr == NULL) { |
| 270 | attr = "#" XML_ATTR_UNAME; |
| 271 | } |
| 272 | |
| 273 | g_hash_table_iter_init(&iter, list1); |
| 274 | while (g_hash_table_iter_next(&iter, NULL, (void **)&node)) { |
| 275 | CRM_CHECK(node != NULL, continue); |
| 276 | score = node_list_attr_score(list2, attr, g_hash_table_lookup(node->details->attrs, attr)); |
| 277 | new_score = merge_weights(factor * score, node->weight); |
| 278 | |
| 279 | if (factor < 0 && score < 0) { |
| 280 | /* Negative preference for a node with a negative score |
| 281 | * should not become a positive preference |
| 282 | * |
| 283 | * TODO - Decide if we want to filter only if weight == -INFINITY |
| 284 | * |
| 285 | */ |
| 286 | crm_trace("%s: Filtering %d + %f*%d (factor * score)", |
| 287 | node->details->uname, node->weight, factor, score); |
| 288 | |
| 289 | } else if (node->weight == INFINITY_HACK) { |
| 290 | crm_trace("%s: Filtering %d + %f*%d (node < 0)", |
| 291 | node->details->uname, node->weight, factor, score); |
| 292 | |
| 293 | } else if (only_positive && new_score < 0 && node->weight > 0) { |
| 294 | node->weight = INFINITY_HACK; |
| 295 | crm_trace("%s: Filtering %d + %f*%d (score > 0)", |
| 296 | node->details->uname, node->weight, factor, score); |
| 297 | |
| 298 | } else if (only_positive && new_score < 0 && node->weight == 0) { |
| 299 | crm_trace("%s: Filtering %d + %f*%d (score == 0)", |
| 300 | node->details->uname, node->weight, factor, score); |
| 301 | |
| 302 | } else { |
| 303 | crm_trace("%s: %d + %f*%d", node->details->uname, node->weight, factor, score); |
| 304 | node->weight = new_score; |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | static GHashTable * |
| 310 | node_hash_dup(GHashTable * hash) |
no test coverage detected