Browse Source

Loosen constraint on the Key type in rb & avl tree

The current constraint on the `init_ordered' function accepts only
numeric types. While one still can init a non-numerically-keyed tree by
passing a comparator explicitly, the reason to disallow non-numeric
ordered types is nowhere to be found.
destroycomputers 1 year ago
parent
commit
de44dd5412
2 changed files with 2 additions and 2 deletions
  1. 1 1
      core/container/avl/avl.odin
  2. 1 1
      core/container/rbtree/rbtree.odin

+ 1 - 1
core/container/avl/avl.odin

@@ -87,7 +87,7 @@ init_cmp :: proc(
 init_ordered :: proc(
 init_ordered :: proc(
 	t: ^$T/Tree($Value),
 	t: ^$T/Tree($Value),
 	node_allocator := context.allocator,
 	node_allocator := context.allocator,
-) where intrinsics.type_is_ordered_numeric(Value) {
+) where intrinsics.type_is_ordered(Value) {
 	init_cmp(t, slice.cmp_proc(Value), node_allocator)
 	init_cmp(t, slice.cmp_proc(Value), node_allocator)
 }
 }
 
 

+ 1 - 1
core/container/rbtree/rbtree.odin

@@ -79,7 +79,7 @@ init_cmp :: proc(t: ^$T/Tree($Key, $Value), cmp_fn: proc(a, b: Key) -> Ordering,
 
 
 // init_ordered initializes a tree containing ordered keys, with
 // init_ordered initializes a tree containing ordered keys, with
 // a comparison function that results in an ascending order sort.
 // a comparison function that results in an ascending order sort.
-init_ordered :: proc(t: ^$T/Tree($Key, $Value), node_allocator := context.allocator) where intrinsics.type_is_ordered_numeric(Key) {
+init_ordered :: proc(t: ^$T/Tree($Key, $Value), node_allocator := context.allocator) where intrinsics.type_is_ordered(Key) {
 	init_cmp(t, slice.cmp_proc(Key), node_allocator)
 	init_cmp(t, slice.cmp_proc(Key), node_allocator)
 }
 }