def rebuild_index(self, txn, name):
if name in self._indexes:<EOL><INDENT>index = self._indexes[name]<EOL>deleted = index.pmap.truncate(txn)<EOL>key_from = struct.pack('<STR_LIT>', self._slot)<EOL>key_to = struct.pack('<STR_LIT>', self._slot + <NUM_LIT:1>)<EOL>cursor = txn._txn.cursor()<EOL>inserted = <NUM_LIT:0><EOL>if cursor.set_range(key_from):<EOL><INDENT>while cursor.key() < key_to:<EOL><INDENT>data = cursor.value()<EOL>if data:<EOL><INDENT>value = self._deserialize_value(data)<EOL>_key = struct.pack('<STR_LIT>', index.pmap._slot) + index.pmap._serialize_key(index.fkey(value))<EOL>_data = index.pmap._serialize_value(value.oid)<EOL>txn.put(_key, _data)<EOL>inserted += <NUM_LIT:1><EOL><DEDENT>if not cursor.next():<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>return deleted, inserted<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>'.format(name))<EOL><DEDENT>
:param txn:
:param name:
:return: