Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Can I merge two trie with pygtrie? #40

Open
hermitgreen opened this issue Mar 21, 2022 · 4 comments
Open

Can I merge two trie with pygtrie? #40

hermitgreen opened this issue Mar 21, 2022 · 4 comments

Comments

@hermitgreen
Copy link

It seems update is just overwrite, same as dict.update

@mina86
Copy link
Contributor

mina86 commented Mar 21, 2022

What do you mean by ‘merge’? Trie implements Mapping interface so update indeed does overwrite keys.

@hermitgreen
Copy link
Author

hermitgreen commented Mar 23, 2022

What do you mean by ‘merge’? Trie implements Mapping interface so update indeed does overwrite keys.

'merge' mean 'update recursively', like merge binary tree

@mina86
Copy link
Contributor

mina86 commented Mar 23, 2022

That still doesn’t explain what you expect to happen when merging to tries which contain the same key.

@hermitgreen
Copy link
Author

hermitgreen commented Mar 28, 2022

That still doesn’t explain what you expect to happen when merging to tries which contain the same key.
Sorry for delay.

While update, a trie contains

{
    "foo": {
          "bar1": "1",
          "bar2": "2"
    }
}

Updated by another trie contains

{
    "foo": {
          "bar3": "3",
    }
}

Would got

{
    "foo": {
          "bar3": "3",
    }
}

Following key would overwrite.
But merge got

{
    "foo": {
          "bar1": "1",
          "bar2": "2",
          "bar3": "3"
    }
}

I mean if tries contains same key, and the key refer a sub trie, then merge would update the sub trie, but not overwrite which will drop out sub trie

mina86 added a commit to mina86/pygtrie that referenced this issue Jul 10, 2022
Trie.merge method allows two tries to be merged structurally which is
often faster than looping over all items and setting them individually
in destination trie.  The operation doesn’t check that the tries are
of the same type so it may result in keys being transformed in one way
or another.

Issue: google#40
mina86 added a commit to mina86/pygtrie that referenced this issue Jul 16, 2022
mina86 added a commit to mina86/pygtrie that referenced this issue Jul 16, 2022
mina86 added a commit to mina86/pygtrie that referenced this issue Jul 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants