ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PhpOffice\PhpSpreadsheet\HashTable Class Reference

T of IComparable More...

+ Collaboration diagram for PhpOffice\PhpSpreadsheet\HashTable:

Public Member Functions

 __construct ($pSource=null)
 Create a new . More...
 
 addFromSource (?array $pSource=null)
 Add HashTable items from source. More...
 
 add (IComparable $pSource)
 Add HashTable item. More...
 
 remove (IComparable $pSource)
 Remove HashTable item. More...
 
 clear ()
 Clear HashTable. More...
 
 count ()
 Count. More...
 
 getIndexForHashCode ($pHashCode)
 Get index for hash code. More...
 
 getByIndex ($pIndex)
 Get by index. More...
 
 getByHashCode ($pHashCode)
 Get by hashcode. More...
 
 toArray ()
 HashTable to array. More...
 
 __clone ()
 Implement PHP __clone to create a deep clone, not just a shallow copy. More...
 

Protected Attributes

 $items = []
 
 $keyMap = []
 

Detailed Description

T of IComparable

Definition at line 8 of file HashTable.php.

Constructor & Destructor Documentation

◆ __construct()

PhpOffice\PhpSpreadsheet\HashTable::__construct (   $pSource = null)

Create a new .

Parameters
T[]$pSource Optional source array to create HashTable from

Definition at line 29 of file HashTable.php.

References PhpOffice\PhpSpreadsheet\HashTable\addFromSource().

30  {
31  if ($pSource !== null) {
32  // Create HashTable
33  $this->addFromSource($pSource);
34  }
35  }
addFromSource(?array $pSource=null)
Add HashTable items from source.
Definition: HashTable.php:42
+ Here is the call graph for this function:

Member Function Documentation

◆ __clone()

PhpOffice\PhpSpreadsheet\HashTable::__clone ( )

Implement PHP __clone to create a deep clone, not just a shallow copy.

Definition at line 169 of file HashTable.php.

References $key.

170  {
171  $vars = get_object_vars($this);
172  foreach ($vars as $key => $value) {
173  // each member of this class is an array
174  if (is_array($value)) {
175  $array1 = $value;
176  foreach ($array1 as $key1 => $value1) {
177  if (is_object($value1)) {
178  $array1[$key1] = clone $value1;
179  }
180  }
181  $this->$key = $array1;
182  }
183  }
184  }
$key
Definition: croninfo.php:18

◆ add()

PhpOffice\PhpSpreadsheet\HashTable::add ( IComparable  $pSource)

Add HashTable item.

Parameters
T$pSourceItem to add

Definition at line 59 of file HashTable.php.

References PhpOffice\PhpSpreadsheet\HashTable\count(), and PhpOffice\PhpSpreadsheet\IComparable\getHashCode().

Referenced by PhpOffice\PhpSpreadsheet\HashTable\addFromSource().

59  : void
60  {
61  $hash = $pSource->getHashCode();
62  if (!isset($this->items[$hash])) {
63  $this->items[$hash] = $pSource;
64  $this->keyMap[count($this->items) - 1] = $hash;
65  }
66  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addFromSource()

PhpOffice\PhpSpreadsheet\HashTable::addFromSource ( ?array  $pSource = null)

Add HashTable items from source.

Parameters
T[]$pSource Source array to create HashTable from

Definition at line 42 of file HashTable.php.

References PhpOffice\PhpSpreadsheet\HashTable\add().

Referenced by PhpOffice\PhpSpreadsheet\HashTable\__construct().

42  : void
43  {
44  // Check if an array was passed
45  if ($pSource == null) {
46  return;
47  }
48 
49  foreach ($pSource as $item) {
50  $this->add($item);
51  }
52  }
add(IComparable $pSource)
Add HashTable item.
Definition: HashTable.php:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clear()

PhpOffice\PhpSpreadsheet\HashTable::clear ( )

Clear HashTable.

Definition at line 96 of file HashTable.php.

96  : void
97  {
98  $this->items = [];
99  $this->keyMap = [];
100  }

◆ count()

PhpOffice\PhpSpreadsheet\HashTable::count ( )

Count.

Returns
int

Definition at line 107 of file HashTable.php.

Referenced by PhpOffice\PhpSpreadsheet\HashTable\add(), and PhpOffice\PhpSpreadsheet\HashTable\remove().

108  {
109  return count($this->items);
110  }
+ Here is the caller graph for this function:

◆ getByHashCode()

PhpOffice\PhpSpreadsheet\HashTable::getByHashCode (   $pHashCode)

Get by hashcode.

Parameters
string$pHashCode
Returns
null|T

Definition at line 147 of file HashTable.php.

Referenced by PhpOffice\PhpSpreadsheet\HashTable\getByIndex().

148  {
149  if (isset($this->items[$pHashCode])) {
150  return $this->items[$pHashCode];
151  }
152 
153  return null;
154  }
+ Here is the caller graph for this function:

◆ getByIndex()

PhpOffice\PhpSpreadsheet\HashTable::getByIndex (   $pIndex)

Get by index.

Parameters
int$pIndex
Returns
null|T

Definition at line 131 of file HashTable.php.

References PhpOffice\PhpSpreadsheet\HashTable\getByHashCode().

132  {
133  if (isset($this->keyMap[$pIndex])) {
134  return $this->getByHashCode($this->keyMap[$pIndex]);
135  }
136 
137  return null;
138  }
getByHashCode($pHashCode)
Get by hashcode.
Definition: HashTable.php:147
+ Here is the call graph for this function:

◆ getIndexForHashCode()

PhpOffice\PhpSpreadsheet\HashTable::getIndexForHashCode (   $pHashCode)

Get index for hash code.

Parameters
string$pHashCode
Returns
int Index

Definition at line 119 of file HashTable.php.

120  {
121  return array_search($pHashCode, $this->keyMap);
122  }

◆ remove()

PhpOffice\PhpSpreadsheet\HashTable::remove ( IComparable  $pSource)

Remove HashTable item.

Parameters
T$pSourceItem to remove

Definition at line 73 of file HashTable.php.

References $key, PhpOffice\PhpSpreadsheet\HashTable\count(), and PhpOffice\PhpSpreadsheet\IComparable\getHashCode().

73  : void
74  {
75  $hash = $pSource->getHashCode();
76  if (isset($this->items[$hash])) {
77  unset($this->items[$hash]);
78 
79  $deleteKey = -1;
80  foreach ($this->keyMap as $key => $value) {
81  if ($deleteKey >= 0) {
82  $this->keyMap[$key - 1] = $value;
83  }
84 
85  if ($value == $hash) {
86  $deleteKey = $key;
87  }
88  }
89  unset($this->keyMap[count($this->keyMap) - 1]);
90  }
91  }
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ toArray()

PhpOffice\PhpSpreadsheet\HashTable::toArray ( )

HashTable to array.

Returns
T[]

Definition at line 161 of file HashTable.php.

References PhpOffice\PhpSpreadsheet\HashTable\$items.

162  {
163  return $this->items;
164  }

Field Documentation

◆ $items

PhpOffice\PhpSpreadsheet\HashTable::$items = []
protected

Definition at line 15 of file HashTable.php.

Referenced by PhpOffice\PhpSpreadsheet\HashTable\toArray().

◆ $keyMap

PhpOffice\PhpSpreadsheet\HashTable::$keyMap = []
protected

Definition at line 22 of file HashTable.php.


The documentation for this class was generated from the following file: