Args: lmdb_path (str): a directory or a file. shuffle (bool): shuffle the keys or not. keys (list[str] or str): list of str as the keys, used only when shuffle is True. It can also be a format string e.g. ``{:0>8d}`` which will be
(self, lmdb_path, shuffle=True, keys=None)
| 69 | mapper function after :class:`LMDBData`. |
| 70 | """ |
| 71 | def __init__(self, lmdb_path, shuffle=True, keys=None): |
| 72 | """ |
| 73 | Args: |
| 74 | lmdb_path (str): a directory or a file. |
| 75 | shuffle (bool): shuffle the keys or not. |
| 76 | keys (list[str] or str): list of str as the keys, used only when shuffle is True. |
| 77 | It can also be a format string e.g. ``{:0>8d}`` which will be |
| 78 | formatted with the indices from 0 to *total_size - 1*. |
| 79 | |
| 80 | If not given, it will then look in the database for ``__keys__`` which |
| 81 | :func:`LMDBSerializer.save` used to store the list of keys. |
| 82 | If still not found, it will iterate over the database to find |
| 83 | all the keys. |
| 84 | """ |
| 85 | self._lmdb_path = lmdb_path |
| 86 | self._shuffle = shuffle |
| 87 | |
| 88 | self._open_lmdb() |
| 89 | self._size = self._txn.stat()['entries'] |
| 90 | self._set_keys(keys) |
| 91 | logger.info("Found {} entries in {}".format(self._size, self._lmdb_path)) |
| 92 | |
| 93 | # Clean them up after finding the list of keys, since we don't want to fork them |
| 94 | self._close_lmdb() |
| 95 | |
| 96 | def _set_keys(self, keys=None): |
| 97 | def find_keys(txn, size): |
nothing calls this directly
no test coverage detected