/** * Delete a given vertex (as reference) * * Searches through the vertices (see above for examples) * and if it finds a match, eliminates the necessary edge * * BECAUSE * * There is no reason for this: * * null v1 * \ / * e1 - ... * * Or this: * * v1 null * \ / * e4 - ... * * Just eliminate the edge. Simple as that :-) * * @param Falcraft\Data\Types\Node\VertexInterface|null $vertex * * @return bool If the operation was successful * */ public function deleteVertex(TypesResource\VertexInterface &$vertex) { $currentEdge = $this->getFirstEdge(); if ($currentEdge->getNextEdge() == null) { // This is the only node, which means it may have null vertices if ($currentEdge->getPrevious() == null) { // if previous is null, we got nothing return false; } else { if ($currentEdge->getPrevious() == $vertex) { // if previous not null and matches if ($currentEdge->getNext() != null) { // make next null, prev => next (bitshift them over) $currentEdge->setPrevious($currentEdge->getNext()); $currentEdge->nullNext(); // $currentEdge->setNext(null); return true; } else { // next is null just delete previous, making nothing $currentEdge->nullPrevious(); // $currentEdge->setPrevious(null); } return true; } else { if ($currentEdge->getNext() == $vertex) { // previous isn't null, and doesn't match, but next matches so... $currentEdge->nullNext(); // $currentEdge->setNext(null); return true; } } } return false; } /* We're working with more than one edge We're still on the first edge though */ if ($currentEdge->getPrevious() == $vertex) { // Disconnect the first edge from the list $currentEdge->getNextEdge()->nullPreviousEdge(); $currentEdge->nullPrevious(); $currentEdge->nullNext(); $currentEdge->nullNextEdge(); // $currentEdge->setPrevious(null); // no memory leaks! - vertex $this->edges->remove($currentEdge); return true; } // Look through the rest of the vertices for a match while ($currentEdge && $currentEdge->getNext() != $vertex) { $currentEdge =& $currentEdge->getNextEdge(); } if ($currentEdge == null) { // vertex not found return false; } if ($currentEdge->getNextEdge() == null) { // the last element in the list $currentEdge->getPreviousEdge()->nullNextEdge(); $currentEdge->nullPreviousEdge(); $currentEdge->nullNext(); $currentEdge->nullPrevious(); $this->edges->remove($currentEdge); // $currentEdge->setPreviousEdge(null); // no memory leaks - edge // $currentEdge->nullNext(); // $currentEdge->nullPrevious(); // $currentEdge->setNext(null); // no memory leaks - vertex return true; } else { if ($currentEdge->getPreviousEdge() == null) { // We're still at the beginning /* v1 *v2* v3 * \ / \ / * (e1) - e2 */ $currentEdge->getNextEdge()->setPrevious($currentEdge->getPrevious()); $currentEdge->getNextEdge()->nullPreviousEdge(); $currentEdge->nullNextEdge(); $currentEdge->nullPrevious(); $currentEdge->nullNext(); $this->edges->remove($currentEdge); return true; } } // Make e2 point to v1 $currentEdge->getNextEdge()->setPrevious($currentEdge->getPrevious()); // delete e1 // $currentEdge->getNextEdge()->setPreviousEdge( $currentEdge->getPreviousEdge() ); $currentEdge->getNextEdge()->setPreviousEdge($currentEdge->getPreviousEdge()); $currentEdge->getPreviousEdge()->setNextEdge($currentEdge->getNextEdge()); // $currentEdge->getPreviousEdge()->setNextEdge( $currentEdge->getNextEdge() ); // $currentEdge->setNextEdge(null); // no memory leaks - edge $currentEdge->nullNext(); $currentEdge->nullPrevious(); $this->edges->remove($currentEdge); // $currentEdge->setNext(null); // no memory leaks - vertex return true; }
/** * Remove a particular extension from the set of allowed extensions * * @return mixed Whatever the remove method in Types\Set returns */ public function removeExtension($extension) { return $this->extensions->remove($extension); }
/** * Detach a listener/observer from the publisher * * Removes the observer from the restricted set * * @param Falcraft\Patterns\Resource\ObserverInterface $observer */ public function detachListener(PatternsResource\ObserverInterface $observer) { $observer->detach($this); $this->observers->remove($observer); }
/** * Detach a listener from ourselves * * so that we no longer notify them when our state changes * * @param Falcraft\Patterns\Resource\ObserverInterface $observer * */ public function detachListener(PatternsResource\ObserverInterface $observer) { if ($this->observers->in($observer)) { $this->observers->remove($observer); } }
/** * Detach from the publisher * */ public function detach(PatternsResource\PublisherInterface $publisher) { if ($this->subject->in($publisher)) { $this->subject->remove($publisher); } }