zeolite-lang-0.16.0.0: lib/container/search-tree.0rp
/* -----------------------------------------------------------------------------
Copyright 2019-2021 Kevin P. Barry
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
----------------------------------------------------------------------------- */
// Author: Kevin P. Barry [ta0kira@gmail.com]
// A binary search tree for key-value storage.
//
// Params:
// - #k: The key type.
// - #v: The value type.
concrete SearchTree<#k,#v> {
refines DefaultOrder<KeyValue<#k,#v>>
refines KVWriter<#k,#v>
refines KVReader<#k,#v>
#k defines LessThan<#k>
// Create an empty tree.
@type new () -> (#self)
// Traverse the tree in the reverse order of defaultOrder().
//
// Notes:
// - Traversal of the entire tree is amortized O(n); however, the cost of any
// particular iteration could be up to O(log n).
// - The overall memory cost is O(log n).
@value reverseOrder () -> (optional Order<KeyValue<#k,#v>>)
// Traverse in the default order.
//
// Notes:
// - This is from DefaultOrder, but is made explicit for documentation.
// - Traversal of the entire tree is amortized O(n); however, the cost of any
// particular iteration could be up to O(log n).
// - The overall memory cost is O(log n).
@value defaultOrder () -> (optional Order<KeyValue<#k,#v>>)
}
// A validated binary search tree for key-value storage.
//
// Params:
// - #k: The key type.
// - #v: The value type.
//
// Notes:
// - This is the same as SearchTree, but it validates the tree structure every
// time there is a modification, which is extremely inefficient. This should
// therefore only be used in tests.
concrete ValidatedTree<#k|#v|> {
refines KVWriter<#k,#v>
refines KVReader<#k,#v>
#k defines LessThan<#k>
// Create an empty tree.
@type new () -> (#self)
}