Currently, the #find operation takes an entire object, even if the comparer only uses a piece of the object. Consider refactoring this to use just a key to find a node.
For example, say we have the following type as the data type for a tree:
interface ITest {
member1: number;
member2: string;
}
function testComparer(a: ITest, b: ITest): number {
return a.member1 - b.member1;
}
Perhaps the only member used in the comparer is #member1. This would be considered the key, while the entire object would be the value. To search for the node containing a specific object, the current API requires a full object passed to #find:
tree.find({ member1: 3, member2: 'this can be anything during find, since the comparer only considers #member1 during lookup'});
Consider refactoring #find such that it only requires the 'key' during lookup:
tree.find(3);
This would likely require a second templated argument throughout the codebase, and would also be a major breaking change. Rather than IBinaryTree<T>, the base signature might be something like IBinaryTree<K,V>. Given the example above, an invocation might look like new BinarySearchTree<number, ITest> rather than the current new BinarySearchTree<ITest>.
Currently, the
#find
operation takes an entire object, even if the comparer only uses a piece of the object. Consider refactoring this to use just a key to find a node.For example, say we have the following type as the data type for a tree:
Perhaps the only member used in the comparer is
#member1
. This would be considered the key, while the entire object would be the value. To search for the node containing a specific object, the current API requires a full object passed to#find
:tree.find({ member1: 3, member2: 'this can be anything during find, since the comparer only considers #member1 during lookup'});
Consider refactoring
#find
such that it only requires the 'key' during lookup:This would likely require a second templated argument throughout the codebase, and would also be a major breaking change. Rather than
IBinaryTree<T>
, the base signature might be something likeIBinaryTree<K,V>
. Given the example above, an invocation might look likenew BinarySearchTree<number, ITest>
rather than the currentnew BinarySearchTree<ITest>
.