function inject(self $ts) { if ($ts->isEmpty()) { return; } if ($this->current instanceof NodeEnd) { $this->jump($this->last->previous); } $a = $this->isEmpty() ? $this->first : $this->current; $b = $ts->first->next; $e = $ts->last->previous; $f = $this->isEmpty() ? $this->last : $this->current->next; self::link($a, $b); self::link($e, $f); }