How many occurrences of item are in the collection?

Comparisons are done with ==

assert [10,20,10].count(10)         == 2

Property definitions

core $ Collection :: count
	# How many occurrences of `item` are in the collection?
	# Comparisons are done with ==
	#
	#     assert [10,20,10].count(10)         == 2
	fun count(item: nullable Object): Int
	do
		var nb = 0
		for i in self do if i == item then nb += 1
		return nb
	end
lib/core/collection/abstract_collection.nit:118,2--127,4

core $ Range :: count
	#     assert [1..10].count(1)	== 1
	#     assert [1..10].count(0)	== 0
	redef fun count(item)
	do
		if has(item) then
			return 1
		else
			return 0
		end
	end
lib/core/collection/range.nit:39,2--48,4

pthreads $ ConcurrentCollection :: count
	redef fun count(e)
	do
		mutex.lock
		var r = real_collection.count(e)
		mutex.unlock
		return r
	end
lib/pthreads/concurrent_collections.nit:84,2--90,4

core $ Ref :: count
	redef fun count(an_item)
	do
		if item == an_item then
			return 1
		else
			return 0
		end
	end
lib/core/collection/abstract_collection.nit:368,2--375,4

core $ AbstractArrayRead :: count
	redef fun count(item)
	do
		var res = 0
		var i = 0
		var l = length
		while i < l do
			if self[i] == item then res += 1
			i += 1
		end
		return res
	end
lib/core/collection/array.nit:52,2--62,4

core $ ArrayMapKeys :: count
	redef fun count(k) do if self.has(k) then return 1 else return 0
lib/core/collection/array.nit:806,2--65

core $ ArrayMapValues :: count
	# O(n)
	redef fun count(item)
	do
		var nb = 0
		for i in self.map._items do if i.second == item then nb += 1
		return nb
	end
lib/core/collection/array.nit:845,2--851,4

core $ HashMapKeys :: count
	redef fun count(k) do if self.has(k) then return 1 else return 0
lib/core/collection/hash_collection.nit:290,2--65

core $ HashMapValues :: count
	redef fun count(item)
	do
		var nb = 0
		var c = self.map._first_item
		while c != null do
			if c._value == item then nb += 1
			c = c._next_item
		end
		return nb
	end
lib/core/collection/hash_collection.nit:311,2--320,4

core $ Set :: count
	# Only 0 or 1
	redef fun count(item)
	do
		if has(item) then
			return 1
		else
			return 0
		end
	end
lib/core/collection/abstract_collection.nit:472,2--480,4

core $ List :: count
	redef fun count(e)
	do
		var nb = 0
		var node = _head
		while node != null do
			if node.item != e then nb += 1
			node = node.next
		end
		return nb
	end
lib/core/collection/list.nit:61,2--70,4