/src/lib/storage/bijective_dictionary/bijective_dictionary_reverser.e
Specman e | 161 lines | 111 code | 26 blank | 24 comment | 3 complexity | 124735ba7ee5435b08f7d35a867a11b1 MD5 | raw file
1-- This file is part of a Liberty Eiffel library. 2-- See the full copyright at the end. 3-- 4class BIJECTIVE_DICTIONARY_REVERSER[V_, K_] 5 -- Allows to view a BIJECTIVE_DICTIONARY[V_, K_] as a BIJECTIVE_DICTIONARY[K_, V_] 6 7inherit 8 BIJECTIVE_DICTIONARY[V_, K_] 9 10create {ANY} 11 from_bijective_dictionary 12 13feature {ANY} 14 from_bijective_dictionary (bijective_dictionary_: like bijective_dictionary) 15 do 16 bijective_dictionary := bijective_dictionary_ 17 end 18 19 count: INTEGER 20 do 21 Result := bijective_dictionary.count 22 end 23 24 has (k: K_): BOOLEAN 25 do 26 Result := bijective_dictionary.has_value(k) 27 end 28 29 at (k: K_): V_ 30 do 31 Result := bijective_dictionary.key_at(k) 32 end 33 34 reference_at (k: K_): V_ 35 do 36 if has(k) then 37 Result := at(k) 38 end 39 end 40 41 fast_has (k: K_): BOOLEAN 42 do 43 Result := bijective_dictionary.fast_has_value(k) 44 end 45 46 fast_at (k: K_): V_ 47 do 48 Result := bijective_dictionary.fast_key_at(k) 49 end 50 51 fast_reference_at (k: K_): V_ 52 do 53 if fast_has(k) then 54 Result := fast_at(k) 55 end 56 end 57 58 has_value (v: V_): BOOLEAN 59 do 60 Result := bijective_dictionary.has(v) 61 end 62 63 key_at (v: V_): K_ 64 do 65 Result := bijective_dictionary.at(v) 66 end 67 68 fast_has_value (v: V_): BOOLEAN 69 do 70 Result := bijective_dictionary.fast_has(v) 71 end 72 73 fast_key_at (v: V_): K_ 74 do 75 Result := bijective_dictionary.fast_at(v) 76 end 77 78 put (v: V_; k: K_) 79 do 80 remove(k) 81 add(v, k) 82 end 83 84 add (v: V_; k: K_) 85 do 86 bijective_dictionary.add(k, v) 87 next_generation 88 end 89 90 remove (k: K_) 91 local 92 v: V_ 93 do 94 if has(k) then 95 v := at(k) 96 bijective_dictionary.remove(v) 97 end 98 next_generation 99 end 100 101 clear_count 102 do 103 bijective_dictionary.clear_count 104 next_generation 105 end 106 107 clear_count_and_capacity 108 do 109 bijective_dictionary.clear_count_and_capacity 110 next_generation 111 end 112 113 capacity: INTEGER 114 do 115 Result := bijective_dictionary.capacity 116 end 117 118 item (index: INTEGER): V_ 119 do 120 Result := bijective_dictionary.key(index) 121 end 122 123 key (index: INTEGER): K_ 124 do 125 Result := bijective_dictionary.item(index) 126 end 127 128 copy (other: like Current) 129 do 130 bijective_dictionary := other.bijective_dictionary 131 end 132 133 internal_key (k: K_): K_ 134 do 135 Result := key_at(at(k)) 136 end 137 138feature {BIJECTIVE_DICTIONARY} 139 bijective_dictionary: BIJECTIVE_DICTIONARY[K_, V_] 140 141end -- class BIJECTIVE_DICTIONARY_REVERSER 142-- 143-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file. 144-- 145-- Permission is hereby granted, free of charge, to any person obtaining a copy 146-- of this software and associated documentation files (the "Software"), to deal 147-- in the Software without restriction, including without limitation the rights 148-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 149-- copies of the Software, and to permit persons to whom the Software is 150-- furnished to do so, subject to the following conditions: 151-- 152-- The above copyright notice and this permission notice shall be included in 153-- all copies or substantial portions of the Software. 154-- 155-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 156-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 157-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 158-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 159-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 160-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 161-- THE SOFTWARE.