Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 320c21f3da02001758cb0fe2a104a6ef336eb592 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*******************************************************************************
 * Copyright (c) 2004, 2008 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

/*
 * Created on Jul 21, 2004
 */
package org.eclipse.cdt.core.parser.util;

import java.util.Collections;
import java.util.List;

/**
 * @author aniefer
 */
public class CharArraySet extends CharTable {
	
    public static final CharArraySet EMPTY_SET = new CharArraySet( 0 ){
        @Override
		public Object clone()               { return this; }
        @Override
		public List<char[]> toList()                { return Collections.emptyList(); }
        @Override
		public void put( char[] key )       { throw new UnsupportedOperationException(); }
        @Override
		public void addAll( List<char[]> list )     { throw new UnsupportedOperationException(); }
        @Override
		public void addAll( CharArraySet set ) { throw new UnsupportedOperationException(); }
    };

	public CharArraySet(int initialSize) {
		super(initialSize);
	}
	
	public void put(char[] key ){
		addIndex(key);
	}
	
	public void addAll( List<char[]> list ){
	    if( list == null )
	        return;
	    
	    int size = list.size();
	    for( int i = 0; i < size; i++ ){
	        addIndex( list.get( i ) );
	    }
	}
	
	public void addAll( CharArraySet set ){
	    if( set == null )
	        return;
	    int size = set.size();
	    for( int i = 0; i < size; i++ ){
	        addIndex( set.keyAt( i ) );
	    }
	}
	
	final public boolean remove( char[] key ) {
		int i = lookup(key);
		if (i < 0)
			return false;

		removeEntry(i);
		return true;
	}

	@Override
	final public void clear(){
	    for( int i = 0; i < keyTable.length; i++ ){
	        keyTable[i] = null;
	        hashTable[ 2*i ] = 0;
	        hashTable[ 2*i + 1 ] = 0;
	        nextTable[i] = 0;
	    }
	    currEntry = -1;
	}
}

Back to the top