author | redestad |
Thu, 07 Nov 2019 12:12:39 +0100 | |
changeset 58962 | 2dcfc28a314d |
parent 53546 | 63eb7e38ce84 |
child 59121 | 7cbffba2156b |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53546 | 2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "libadt/vectset.hpp" |
|
27 |
#include "memory/allocation.inline.hpp" |
|
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47216
diff
changeset
|
28 |
#include "memory/arena.hpp" |
1 | 29 |
|
58962 | 30 |
VectorSet::VectorSet(Arena *arena) { |
31 |
_set_arena = arena; |
|
1 | 32 |
size = 2; // Small initial size |
24425 | 33 |
data = (uint32_t *)_set_arena->Amalloc(size*sizeof(uint32_t)); |
1 | 34 |
data[0] = 0; // No elements |
35 |
data[1] = 0; |
|
36 |
} |
|
37 |
||
38 |
// Expand the existing set to a bigger size |
|
58962 | 39 |
void VectorSet::grow(uint newsize) { |
40 |
newsize = (newsize+31) >> 5; |
|
1 | 41 |
uint x = size; |
58962 | 42 |
while (x < newsize) { |
43 |
x <<= 1; |
|
44 |
} |
|
24425 | 45 |
data = (uint32_t *)_set_arena->Arealloc(data, size*sizeof(uint32_t), x*sizeof(uint32_t)); |
58962 | 46 |
memset((char*)(data + size), 0, (x - size) * sizeof(uint32_t)); |
1 | 47 |
size = x; |
48 |
} |
|
49 |
||
50 |
// Insert a member into an existing Set. |
|
58962 | 51 |
void VectorSet::insert(uint elem) { |
52 |
uint word = elem >> 5; |
|
53 |
uint32_t mask = 1L << (elem & 31); |
|
54 |
if (word >= size) { |
|
55 |
grow(elem + 1); |
|
1 | 56 |
} |
58962 | 57 |
data[word] |= mask; |
1 | 58 |
} |
59 |
||
60 |
// Clear a set |
|
58962 | 61 |
void VectorSet::clear() { |
1 | 62 |
if( size > 100 ) { // Reclaim storage only if huge |
24425 | 63 |
FREE_RESOURCE_ARRAY(uint32_t,data,size); |
1 | 64 |
size = 2; // Small initial size |
24425 | 65 |
data = NEW_RESOURCE_ARRAY(uint32_t,size); |
1 | 66 |
} |
58962 | 67 |
memset(data, 0, size*sizeof(uint32_t)); |
1 | 68 |
} |
69 |
||
58962 | 70 |
// Return true if the set is empty |
71 |
bool VectorSet::is_empty() const { |
|
72 |
for (uint32_t i = 0; i < size; i++) { |
|
73 |
if (data[i] != 0) { |
|
74 |
return false; |
|
75 |
} |
|
76 |
} |
|
77 |
return true; |
|
10975 | 78 |
} |
79 |
||
58962 | 80 |
int VectorSet::hash() const { |
81 |
uint32_t _xor = 0; |
|
82 |
uint lim = ((size < 4) ? size : 4); |
|
83 |
for (uint i = 0; i < lim; i++) { |
|
84 |
_xor ^= data[i]; |
|
85 |
} |
|
86 |
return (int)_xor; |
|
1 | 87 |
} |