change key types to any

This commit is contained in:
2025-08-08 12:06:51 +08:00
parent 45aaa4bf1a
commit 6787c1817f

View File

@@ -5,7 +5,7 @@ import (
) )
// Node is a node on the binary search tree. // Node is a node on the binary search tree.
type Node[K comparable, V any, C Sorter[K]] struct { type Node[K, V any, C Sorter[K]] struct {
lson, rson *Node[K, V, C] lson, rson *Node[K, V, C]
parent *Node[K, V, C] parent *Node[K, V, C]
bal uint32 // for treap balancing bal uint32 // for treap balancing
@@ -23,7 +23,7 @@ func (n *Node[K, V, C]) Key() K {
// addresses and don't work with values. // addresses and don't work with values.
// //
// The zero value is a usable, empty tree. // The zero value is a usable, empty tree.
type Tree[K comparable, V any, C Sorter[K]] struct { type Tree[K, V any, C Sorter[K]] struct {
root *Node[K, V, C] root *Node[K, V, C]
} }
@@ -58,6 +58,8 @@ func (t *Tree[K, V, C]) InsertNode(key K, value V) (node *Node[K, V, C], is_adde
// realInsertNode recursivly searches and tries to insert the new node. // realInsertNode recursivly searches and tries to insert the new node.
// If the key is found, it's passed into *result. // If the key is found, it's passed into *result.
//
// Returns the new node that should be placed in CUR's place (usually itself).
func (t *Tree[K, V, C]) realInsertNode(cur, parent *Node[K, V, C], key K, value V, result **Node[K, V, C], is_added *bool) (node *Node[K, V, C]) { func (t *Tree[K, V, C]) realInsertNode(cur, parent *Node[K, V, C], key K, value V, result **Node[K, V, C], is_added *bool) (node *Node[K, V, C]) {
var c C var c C
if cur == nil { if cur == nil {