key
?var x = new HashMap[String, Int]
x["four"] = 4
assert x.has_key("four") == true
assert x.has_key("five") == false
By default it is a synonymous to keys.has
but could be redefined with a direct implementation.
# Is there an item associated with `key`?
#
# var x = new HashMap[String, Int]
# x["four"] = 4
# assert x.has_key("four") == true
# assert x.has_key("five") == false
#
# By default it is a synonymous to `keys.has` but could be redefined with a direct implementation.
fun has_key(key: nullable Object): Bool do return self.keys.has(key)
lib/core/collection/abstract_collection.nit:572,2--580,69
# O(n) in worst case, average is O(h) with h: tree height
#
# var tree = new BinTreeMap[Int, String]
# assert not tree.has_key(1)
# for i in [4, 2, 1, 5, 3] do tree[i] = "n{i}"
# assert not tree.has_key(0)
# assert tree.has_key(2)
# assert not tree.has_key(6)
redef fun has_key(key) do
if is_empty then return false
var res = search_down(root.as(not null), key)
if res != null then
cache_node = res
return true
end
return false
end
lib/trees/bintree.nit:60,2--76,4
# Is there a property located at `key`?
#
# Returns `true` if the `key` is not found of if its associated value is `null`.
#
# ~~~
# var ini = new IniFile.from_string("""
# key=value1
# [section1]
# key=value2
# [section2]
# key=value3
# """)
# assert ini.has_key("key")
# assert ini.has_key("section1.key")
# assert ini.has_key("section2.key")
# assert not ini.has_key("section1")
# assert not ini.has_key("not.found")
# ~~~
redef fun has_key(key) do return self[key] != null
lib/ini/ini.nit:178,2--196,51