Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
pool.php
1
<?php
2
namespace
Bitrix\Location\Common
;
3
8
class
Pool
9
{
11
protected
$poolSize
= 0;
13
protected
$items
= [];
14
20
public
function
__construct
(
int
$poolSize
)
21
{
22
$this->poolSize =
$poolSize
;
23
}
24
28
public
function
getItems
(): array
29
{
30
return
$this->items
;
31
}
32
33
public
function
cleanItems
(): void
34
{
35
$this->items = [];
36
}
37
41
public
function
setItems
(array
$items
): void
42
{
43
$this->items =
$items
;
44
}
45
50
public
function
getItem
(
string
$index)
51
{
52
$result =
null
;
53
54
if
(isset($this->items[$index]))
55
{
56
$result = $this->items[$index];
57
//come up used items
58
unset($this->items[$index]);
59
$this->items[$index] = $result;
60
}
61
62
return
$result;
63
}
64
69
public
function
addItem
(
string
$index, $value): void
70
{
71
$this->items[$index] = $value;
72
$delta = count($this->items) -
$this->poolSize
;
73
74
if
($delta > 0)
75
{
76
$this->items = $this->
decreaseSize
($delta, $this->items);
77
}
78
}
79
83
public
function
getItemsCount
(): int
84
{
85
return
count($this->items);
86
}
87
91
public
function
deleteItem
(
string
$index): void
92
{
93
if
(isset($this->items[$index]))
94
{
95
unset($this->items[$index]);
96
}
97
}
98
104
protected
function
decreaseSize
(
int
$delta, array
$items
): array
105
{
106
if
($delta <= 0 || count(
$items
) <= 0)
107
{
108
return
$items
;
109
}
110
111
do
112
{
113
reset(
$items
);
114
unset(
$items
[key(
$items
)]);
115
$delta--;
116
}
117
while
($delta > 0);
118
119
return
$items
;
120
}
121
}
Bitrix\Location\Common\Pool
Definition
pool.php:9
Bitrix\Location\Common\Pool\addItem
addItem(string $index, $value)
Definition
pool.php:69
Bitrix\Location\Common\Pool\cleanItems
cleanItems()
Definition
pool.php:33
Bitrix\Location\Common\Pool\$poolSize
$poolSize
Definition
pool.php:11
Bitrix\Location\Common\Pool\setItems
setItems(array $items)
Definition
pool.php:41
Bitrix\Location\Common\Pool\getItem
getItem(string $index)
Definition
pool.php:50
Bitrix\Location\Common\Pool\$items
$items
Definition
pool.php:13
Bitrix\Location\Common\Pool\__construct
__construct(int $poolSize)
Definition
pool.php:20
Bitrix\Location\Common\Pool\deleteItem
deleteItem(string $index)
Definition
pool.php:91
Bitrix\Location\Common\Pool\getItems
getItems()
Definition
pool.php:28
Bitrix\Location\Common\Pool\decreaseSize
decreaseSize(int $delta, array $items)
Definition
pool.php:104
Bitrix\Location\Common\Pool\getItemsCount
getItemsCount()
Definition
pool.php:83
Bitrix\Location\Common
Definition
baseservice.php:3
modules
location
lib
common
pool.php
Создано системой
1.10.0