Property definitions

core $ HashSet :: defaultinit
# A `Set` implemented with a hash table.
# Keys of such a map cannot be null and require a working `hash` method
class HashSet[E]
	super Set[E]
	super HashCollection[E]

	redef type N: HashSetNode[E] is fixed

	redef fun length do return _the_length

	redef fun is_empty do return _the_length == 0

	redef fun first
	do
		assert _the_length > 0
		return _first_item._key
	end

	redef fun has(item)
	do
		return node_at(item) != null
	end

	redef fun add(item)
	do
		if _capacity == 0 then enlarge(17) # 17 because magic in `store`
		var i = index_at(item)
		var c = node_at_idx(i, item)
		if c != null then
			c._key = item
		else
			store(i,new HashSetNode[E](item))
		end
	end

	redef fun remove(item) do remove_node(item)

	redef fun clear do raz

	redef fun iterator do return new HashSetIterator[E](self)

	init
	do
		_capacity = 0
		_the_length = 0
	end

	# Build a list filled with the items of `coll`.
	init from(coll: Collection[E]) do
		init
		add_all(coll)
	end

	redef fun new_set do return new HashSet[E]
end
lib/core/collection/hash_collection.nit:424,1--478,3