mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-21 04:09:55 +09:00
- 2022년 3월 개발팀 결정사항 적용 - 모듈 등 서드파티 자료 개발시 composer를 사용하면 상위 경로에 있는 코어의 composer.json을 수정하고, 코어의 vendor 디렉토리를 건드리는 것이 기본값임 - 이를 방지하기 위해 코어의 composer.json과 vendor를 common 디렉토리 안으로 이동하여, 모듈 경로에서 상위 폴더로 인식하지 않도록 함
56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* A simple array-backed queue, based off of the classic Okasaki
|
|
* persistent amortized queue. The basic idea is to maintain two
|
|
* stacks: an input stack and an output stack. When the output
|
|
* stack runs out, reverse the input stack and use it as the output
|
|
* stack.
|
|
*
|
|
* We don't use the SPL implementation because it's only supported
|
|
* on PHP 5.3 and later.
|
|
*
|
|
* Exercise: Prove that push/pop on this queue take amortized O(1) time.
|
|
*
|
|
* Exercise: Extend this queue to be a deque, while preserving amortized
|
|
* O(1) time. Some care must be taken on rebalancing to avoid quadratic
|
|
* behaviour caused by repeatedly shuffling data from the input stack
|
|
* to the output stack and back.
|
|
*/
|
|
class HTMLPurifier_Queue {
|
|
private $input;
|
|
private $output;
|
|
|
|
public function __construct($input = array()) {
|
|
$this->input = $input;
|
|
$this->output = array();
|
|
}
|
|
|
|
/**
|
|
* Shifts an element off the front of the queue.
|
|
*/
|
|
public function shift() {
|
|
if (empty($this->output)) {
|
|
$this->output = array_reverse($this->input);
|
|
$this->input = array();
|
|
}
|
|
if (empty($this->output)) {
|
|
return NULL;
|
|
}
|
|
return array_pop($this->output);
|
|
}
|
|
|
|
/**
|
|
* Pushes an element onto the front of the queue.
|
|
*/
|
|
public function push($x) {
|
|
array_push($this->input, $x);
|
|
}
|
|
|
|
/**
|
|
* Checks if it's empty.
|
|
*/
|
|
public function isEmpty() {
|
|
return empty($this->input) && empty($this->output);
|
|
}
|
|
}
|