BadVPN – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 <?php
2  
3 /*
4 File: set.so.php
5 License: GPL
6 Purpose: We should really have a "set" data type. It's too useful.
7 */
8  
9 class set {
10 function __construct($list=array()) { $this->data = array_count_values($list); }
11 function has($item) { return isset($this->data[$item]); }
12 function add($item) { $this->data[$item] = true; }
13 function del($item) { unset($this->data[$item]); return $item;}
14 function all() { return array_keys($this->data); }
15 function one() { return key($this->data); }
16 function count() { return count($this->data); }
17 function pop() { return $this->del($this->one()); }
18 function union($that) {
19 $progress = false;
20 foreach ($that->all() as $item) if (!$this->has($item)) {
21 $this->add($item);
22 $progress = true;
23 }
24 return $progress;
25 }
26 function text() {
27 return ' { '.implode(' ', $this->all()).' } ';
28 }
29 }