Skip to content

put function should copy Prefix #10

@emrekzd

Description

@emrekzd

Prefix is a named type of []byte, so passing it to put function (called by Set and Insert) passes a reference to the slice value. put should make a copy of the key:

    t := patricia.NewTrie()

    key := patricia.Prefix("foo")
    t.Insert(key, true)

    // alter the key slice
    key[0] = 'b'

    fmt.Println("boo key: ", t.Get(patricia.Prefix("boo")))
    fmt.Println("foo key: ", t.Get(patricia.Prefix("foo")))

Output:

    boo key:  true
    foo key:  <nil>

Sending a pull request for a fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions