def count(self, txn, prefix=None):
key_from = struct.pack('<STR_LIT>', self._slot)<EOL>if prefix:<EOL><INDENT>key_from += self._serialize_key(prefix)<EOL><DEDENT>kfl = len(key_from)<EOL>cnt = <NUM_LIT:0><EOL>cursor = txn._txn.cursor()<EOL>has_more = cursor.set_range(key_from)<EOL>while has_more:<EOL><INDENT>_key = cursor.key()<EOL>_prefix = _key[:kfl]<EOL>if _prefix != key_from:<EOL><INDENT>break<EOL><DEDENT>cnt += <NUM_LIT:1><EOL>has_more = cursor.next()<EOL><DEDENT>return cnt<EOL>
Count number of records in the persistent map. When no prefix
is given, the total number of records is returned. When a prefix
is given, only the number of records with keys that have this
prefix are counted.

:param txn: The transaction in which to run.
:type txn: :class:`zlmdb.Transaction`

:param prefix: The key prefix of records to count.
:type prefix: object

:returns: The number of records.
:rtype: int