/src/lib/storage/set/abstract_avl_set.e
Specman e | 120 lines | 83 code | 14 blank | 23 comment | 4 complexity | 2966ef3021f4afcc0c1efa1e52bcb975 MD5 | raw file
1-- This file is part of a Liberty Eiffel library. 2-- See the full copyright at the end. 3-- 4deferred class ABSTRACT_AVL_SET[E_] 5 6inherit 7 SET[E_] 8 redefine new_iterator 9 end 10 11insert 12 AVL_TREE[E_] 13 rename 14 set_value_and_key as set_item 15 export 16 {ITERATOR_ON_AVL_SET} root 17 end 18 19feature {ANY} 20 new_iterator: ITERATOR[E_] 21 do 22 create {ITERATOR_ON_AVL_SET[E_]} Result.make(Current) 23 end 24 25 add (e: like item) 26 do 27 item_memory := e 28 root := do_insert(root) 29 next_generation 30 end 31 32 fast_add (e: like item) 33 do 34 item_memory := e 35 root := fast_do_insert(root) 36 next_generation 37 end 38 39 clear_count, clear_count_and_capacity 40 do 41 if not is_empty then 42 clear_nodes(root) 43 root := Void 44 count := 0 45 map_dirty := True 46 end 47 next_generation 48 end 49 50 reference_at (e: like item): like item 51 local 52 n: ABSTRACT_AVL_SET_NODE[E_] 53 do 54 if root /= Void then 55 n := root.at(e) 56 if n /= Void then 57 Result := n.item 58 end 59 end 60 end 61 62 item (index: INTEGER): E_ 63 do 64 if map_dirty then 65 build_map 66 end 67 Result := map.item(index - 1).item 68 end 69 70feature {} 71 set_item (n: like a_new_node) 72 do 73 n.set(item_memory) 74 end 75 76 set_value (n: like a_new_node) 77 do 78 end 79 80 a_new_node: ABSTRACT_AVL_SET_NODE[E_] 81 deferred 82 end 83 84 exchange_and_discard (n1, n2: like a_new_node) 85 do 86 map_dirty := True 87 n1.set_item(n2.item) 88 rebalance := True 89 count := count - 1 90 discard_node(n2) 91 end 92 93feature {} 94 make 95 do 96 create map.make(0) 97 next_generation 98 end 99 100end -- class ABSTRACT_AVL_SET 101-- 102-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file. 103-- 104-- Permission is hereby granted, free of charge, to any person obtaining a copy 105-- of this software and associated documentation files (the "Software"), to deal 106-- in the Software without restriction, including without limitation the rights 107-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 108-- copies of the Software, and to permit persons to whom the Software is 109-- furnished to do so, subject to the following conditions: 110-- 111-- The above copyright notice and this permission notice shall be included in 112-- all copies or substantial portions of the Software. 113-- 114-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 115-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 116-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 117-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 118-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 119-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 120-- THE SOFTWARE.