<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _add_index(self, index):
 """ Adds an index to the table. :param index: The index to add :type index: Index :rtype: Table """

        index_name = index.get_name()
        index_name = self._normalize_identifier(index_name)
        replaced_implicit_indexes = []

        for name, implicit_index in self._implicit_indexes.items():
            if implicit_index.is_fullfilled_by(index) and name in self._indexes:
                replaced_implicit_indexes.append(name)

        already_exists = (
            index_name in self._indexes
            and index_name not in replaced_implicit_indexes
            or self._primary_key_name is not False
            and index.is_primary()
        )
        if already_exists:
            raise IndexAlreadyExists(index_name, self._name)

        for name in replaced_implicit_indexes:
            del self._indexes[name]
            del self._implicit_indexes[name]

        if index.is_primary():
            self._primary_key_name = index_name

        self._indexes[index_name] = index

        return self