Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 11, 2025

Summary

Fixes the Count logic bug described in issue #359 where the Count method had incorrect logic when either source or target was 'any'.

Problem Description

The bug was in the Count method (and related Each method) where when checking links with partial restrictions:

  • The original code used a single value variable that got overwritten when both conditions were checked
  • If source == any, value was set to target
  • If target == any, value was overwritten with source, losing the previous assignment
  • This caused incorrect matching behavior

Solution

Changed the logic to handle each case separately:

  • Before: Used single variable that got overwritten
  • After: Handle source==any and target==any cases independently with separate conditional blocks

Files Changed

C# Implementation

  • csharp/Platform.Data.Doublets/Memory/Split/Generic/SplitMemoryLinksBase.cs (lines 393-406)

C++ Implementation

  • cpp/Platform.Data.Doublets/Memory/Split/Generic/SplitMemoryLinksBase.h (3 locations):
    • First Count method (lines 318-331)
    • Second Count method (lines 532-545)
    • Each method (lines 729-742)

Test/Example

  • Added examples/count_logic_test.cs demonstrating the fix with test cases

Code Changes

Old (buggy) logic:

var value = default(TLinkAddress);
if ((source == any))
{
    value = target;
}
if ((target == any))  // This overwrites value!
{
    value = source;
}
if ((storedLinkValue.Source == value) || (storedLinkValue.Target == value))
{
    return GetOne();
}

New (fixed) logic:

if ((source == any))
{
    if ((storedLinkValue.Target == target))
    {
        return GetOne();
    }
}
if ((target == any))
{
    if ((storedLinkValue.Source == source))
    {
        return GetOne();
    }
}

Test Plan

  • Added example test case showing the difference between old and new logic
  • The example demonstrates specific scenarios where the bug would manifest
  • All changes maintain the same public API and behavior for correct cases

Fixes #359

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #359
@konard konard self-assigned this Sep 11, 2025
konard and others added 2 commits September 11, 2025 14:39
Resolves issue #359 where Count method had incorrect logic when either
source or target was 'any'. The previous implementation used a single
variable that got overwritten, causing incorrect results.

Changes:
- C#: Fixed SplitMemoryLinksBase.cs Count method (lines 393-406)
- C++: Fixed SplitMemoryLinksBase.h Count and Each methods (3 locations)
- Added example test demonstrating the fix

The bug occurred when checking links with partial restrictions:
- Before: Used single 'value' variable that got overwritten
- After: Handle source==any and target==any cases separately

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Repair Count logic Fix Count logic bug in C# and C++ implementations Sep 11, 2025
@konard konard marked this pull request as ready for review September 11, 2025 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Repair Count logic

2 participants