com.ibm.wala.util.intset.MutableSparseLongSetFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.ibm.wala.util Show documentation
Show all versions of com.ibm.wala.util Show documentation
T. J. Watson Libraries for Analysis
The newest version!
/*
* Copyright (c) 2002 - 2006 IBM Corporation.
* 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
*/
package com.ibm.wala.util.intset;
import java.util.Arrays;
import java.util.TreeSet;
/** An object that creates mutable sparse int sets. */
public class MutableSparseLongSetFactory implements MutableLongSetFactory {
/**
* @throws IllegalArgumentException if set is null
*/
@Override
public MutableLongSet make(long[] set) {
if (set == null) {
throw new IllegalArgumentException("set is null");
}
if (set.length == 0) {
return new MutableSparseLongSet();
} else {
// XXX not very efficient.
TreeSet T = new TreeSet<>();
for (long element : set) {
T.add(element);
}
long[] copy = new long[T.size()];
int i = 0;
for (Long I : T) {
copy[i++] = I;
}
MutableSparseLongSet result = new MutableSparseLongSet(copy);
return result;
}
}
@Override
public MutableLongSet parse(String string) throws NumberFormatException {
int[] backingStore = SparseIntSet.parseIntArray(string);
long[] bs = Arrays.stream(backingStore).asLongStream().toArray();
return new MutableSparseLongSet(bs);
}
@Override
public MutableLongSet makeCopy(LongSet x) throws IllegalArgumentException {
if (x == null) {
throw new IllegalArgumentException("x == null");
}
return MutableSparseLongSet.make(x);
}
@Override
public MutableLongSet make() {
return new MutableSparseLongSet();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy