Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add merging to V3 resolve and node search #1518

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

n-h-diaz
Copy link
Contributor

No description provided.

@n-h-diaz n-h-diaz requested a review from keyurva February 13, 2025 17:51
Copy link
Contributor

@keyurva keyurva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

result := allResp[i].Results[counter]

// Check if result was already added.
key, err := proto.Marshal(result)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering how expensive this check is and whether we need to check all? If we do, can we base it on result.Node.Dcid?

complete := map[int]bool{}
counter := 0
loop:
for {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit and optional: I prompted gemini on different ways of merging arrays based on our requirements and it came up with the following. Feel free to use it and perfectly fine to ignore (the logic in the PR works):

func mergeArraysClean(arrays [][]int, maxNumResults int) []int {
        merged := make([]int, 0, maxNumResults)

        for len(merged) < maxNumResults && len(arrays) > 0 {
                newArrays := make([][]int, 0, len(arrays)) // Create a new slice for remaining arrays
                added := false

                for _, arr := range arrays {
                        if len(arr) > 0 {
                                merged = append(merged, arr[0])
                                added = true
                                if len(merged) >= maxNumResults {
                                        return merged
                                }
                                if len(arr) > 1 {
                                        newArrays = append(newArrays, arr[1:]) // Add remaining elements to the new slice
                                }
                        }
                }
                if !added {
                        break;
                }

                arrays = newArrays // Update arrays with the remaining sub-arrays
        }

        return merged
}

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.

2 participants