当前路径:vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/HashTable.php <?php namespace PhpOffice\PhpSpreadsheet; class HashTable { /** * HashTable elements. * * @var IComparable[] */ protected $items = []; /** * HashTable key map. * * @var string[] */ protected $keyMap = []; /** * Create a new \PhpOffice\PhpSpreadsheet\HashTable. * * @param IComparable[] $pSource Optional source array to create HashTable from */ public function __construct($pSource = null) { if ($pSource !== null) { // Create HashTable $this->addFromSource($pSource); } } /** * Add HashTable items from source. * * @param IComparable[] $pSource Source array to create HashTable from */ public function addFromSource(?array $pSource = null): void { // Check if an array was passed if ($pSource == null) { return; } foreach ($pSource as $item) { $this->add($item); } } /** * Add HashTable item. * * @param IComparable $pSource Item to add */ public function add(IComparable $pSource): void { $hash = $pSource->getHashCode(); if (!isset($this->items[$hash])) { $this->items[$hash] = $pSource; $this->keyMap[count($this->items) - 1] = $hash; } } /** * Remove HashTable item. * * @param IComparable $pSource Item to remove */ public function remove(IComparable $pSource): void { $hash = $pSource->getHashCode(); if (isset($this->items[$hash])) { unset($this->items[$hash]); $deleteKey = -1; foreach ($this->keyMap as $key => $value) { if ($deleteKey >= 0) { $this->keyMap[$key - 1] = $value; } if ($value == $hash) { $deleteKey = $key; } } unset($this->keyMap[count($this->keyMap) - 1]); } } /** * Clear HashTable. */ public function clear(): void { $this->items = []; $this->keyMap = []; } /** * Count. * * @return int */ public function count() { return count($this->items); } /** * Get index for hash code. * * @param string $pHashCode * * @return int Index */ public function getIndexForHashCode($pHashCode) { return array_search($pHashCode, $this->keyMap); } /** * Get by index. * * @param int $pIndex * * @return IComparable */ public function getByIndex($pIndex) { if (isset($this->keyMap[$pIndex])) { return $this->getByHashCode($this->keyMap[$pIndex]); } return null; } /** * Get by hashcode. * * @param string $pHashCode * * @return IComparable */ public function getByHashCode($pHashCode) { if (isset($this->items[$pHashCode])) { return $this->items[$pHashCode]; } return null; } /** * HashTable to array. * * @return IComparable[] */ public function toArray() { return $this->items; } /** * Implement PHP __clone to create a deep clone, not just a shallow copy. */ public function __clone() { $vars = get_object_vars($this); foreach ($vars as $key => $value) { if (is_object($value)) { $this->$key = clone $value; } } } }
相关源码
- 可旋转的彩色立方体C#源代码2021-10-29
- 在线考试系统2021-10-15
- EduSoho开源网校系统源码2019-06-27
- 仿拼多多小程序商城源码2019-06-06
- PHP5网站运行监测系统源码2017-04-14
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途)
地址:北京市海淀区大恒科技大厦五层 邮编:100080
Floor 5th,Daheng Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2022. 京ICP备09089570号 | 京公网安备11010702000869号
联系电话(Tel):4008-010-151(免长途)
地址:北京市海淀区大恒科技大厦五层 邮编:100080
Floor 5th,Daheng Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2022. 京ICP备09089570号 | 京公网安备11010702000869号