FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ArrayOperation.php
1 <?php
2 /*
3 Copyright (C) 2014, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 as published by the Free Software Foundation.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 namespace Fossology\Lib\Util;
20 
21 use Closure;
22 
24 {
29  public static function getMultiplicityOfValues($allValues)
30  {
31  $uniqueValues = array_unique($allValues);
32  $valueMultiplicityMap = array();
33 
34  foreach ($uniqueValues as $value) {
35  $count = 0;
36  foreach ($allValues as $candidate) {
37  if ($value == $candidate) {
38  $count ++;
39  }
40  }
41  $valueMultiplicityMap[$value] = $count;
42  }
43 
44  return $valueMultiplicityMap;
45  }
46 
47  public static function callChunked(Closure $callback, $values, $chunkSize)
48  {
49  if ($chunkSize <= 0) {
50  throw new \InvalidArgumentException('chunk size should be positive');
51  }
52  $result = array();
53  for ($offset = 0; $offset < count($values); $offset += $chunkSize) {
54  $result = array_merge($result,
55  $callback(array_slice($values, $offset, $chunkSize)));
56  }
57  return $result;
58  }
59 
60  public static function multiSearch($needles,$haystack)
61  {
62  foreach ($needles as $needle) {
63  $index = array_search($needle, $haystack);
64  if ($index !== false) {
65  return $index;
66  }
67  }
68  return false;
69  }
70 }
static getMultiplicityOfValues($allValues)