Skip to content

Commit a008c87

Browse files
Update jellyfish.c
1 parent 2a68141 commit a008c87

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

code/logic/jellyfish.c

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -904,43 +904,42 @@ int fossil_jellyfish_audit(const fossil_jellyfish_chain_t *chain) {
904904
return issues;
905905
}
906906

907-
int fossil_jellyfish_prune(fossil_jellyfish_chain_t *chain, float min_confidence) {
908-
if (!chain) return 0;
909-
int pruned = 0;
907+
int fossil_jellyfish_prune(fossil_jellyfish_chain_t *chain, float *min_conf) {
908+
if (!chain || chain->count == 0 || !min_conf)
909+
return 0;
910910

911-
// Per-type minimum confidence thresholds (can be adjusted as needed)
912-
const float min_conf[11] = {
913-
min_confidence, // UNKNOWN
914-
min_confidence, // OBSERVED
915-
min_confidence + 0.05f, // INFERRED
916-
min_confidence + 0.10f, // VALIDATED
917-
min_confidence + 0.05f, // CORRECTED
918-
min_confidence + 0.05f, // ASSUMED
919-
min_confidence, // RETRACTED
920-
min_confidence + 0.10f, // EXPERIMENTAL
921-
min_confidence + 0.05f, // GUIDED
922-
min_confidence + 0.20f, // IMMUTABLE (rarely pruned)
923-
min_confidence - 0.03f // ARCHIVED (allow slightly lower)
924-
};
911+
int pruned = 0;
912+
int i = 0;
925913

926-
for (size_t i = 0; i < chain->count; ) {
914+
while (i < chain->count) {
927915
fossil_jellyfish_block_t *block = &chain->memory[i];
928-
int t = (block->block_type >= 0 && block->block_type <= 10) ? block->block_type : 0;
916+
int t = block->type;
929917

930-
// Only prune if not immutable and confidence below per-type threshold
931-
if (!block->attributes.valid || block->attributes.immutable ||
932-
block->attributes.confidence >= min_conf[t]) {
918+
// 1. Skip immutable blocks entirely
919+
if (block->attributes.immutable) {
933920
i++;
934921
continue;
935922
}
936923

937-
// Mark as pruned and invalid, then shift the rest down
938-
block->attributes.pruned = 1;
939-
block->attributes.valid = 0;
940-
memmove(&chain->memory[i], &chain->memory[i + 1], sizeof(fossil_jellyfish_block_t) * (chain->count - i - 1));
941-
chain->count--;
942-
pruned++;
943-
// Do not increment i, as we now have a new block at this index
924+
// 2. If the block is invalid OR below confidence → prune it
925+
if (!block->attributes.valid || block->attributes.confidence < min_conf[t]) {
926+
block->attributes.pruned = 1;
927+
block->attributes.valid = 0;
928+
929+
// Shift memory down to overwrite the pruned block
930+
if (i < chain->count - 1) {
931+
memmove(&chain->memory[i],
932+
&chain->memory[i + 1],
933+
sizeof(fossil_jellyfish_block_t) * (chain->count - i - 1));
934+
}
935+
936+
chain->count--;
937+
pruned++;
938+
// Note: do NOT increment i here, because we need to check the new block at position i
939+
} else {
940+
// Keep the block → move to the next
941+
i++;
942+
}
944943
}
945944

946945
return pruned;

0 commit comments

Comments
 (0)