001/* Copyright (C) 2013 TU Dortmund 002 * This file is part of AutomataLib, http://www.automatalib.net/. 003 * 004 * AutomataLib is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU Lesser General Public 006 * License version 3.0 as published by the Free Software Foundation. 007 * 008 * AutomataLib is distributed in the hope that it will be useful, 009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 011 * Lesser General Public License for more details. 012 * 013 * You should have received a copy of the GNU Lesser General Public 014 * License along with AutomataLib; if not, see 015 * http://www.gnu.de/documents/lgpl.en.html. 016 */ 017package net.automatalib.ts.powerset; 018 019import java.util.AbstractSet; 020import java.util.ArrayList; 021import java.util.BitSet; 022import java.util.Iterator; 023import java.util.List; 024 025public class FastPowersetState<S> extends AbstractSet<S> { 026 027 private final BitSet bs = new BitSet(); 028 private final List<S> contents 029 = new ArrayList<S>(); 030 031 public void add(S state, int id) { 032 if(bs.get(id)) 033 return; 034 bs.set(id); 035 contents.add(state); 036 } 037 038 @Override 039 public boolean remove(Object o) { 040 throw new UnsupportedOperationException(); 041 } 042 043 @Override 044 public Iterator<S> iterator() { 045 return contents.iterator(); 046 } 047 048 @Override 049 public int size() { 050 return contents.size(); 051 } 052 053 054 @Override 055 public int hashCode() { 056 return bs.hashCode(); 057 } 058 059 @Override 060 public boolean equals(Object obj) { 061 if (this == obj) 062 return true; 063 if(obj == null) 064 return false; 065 if (getClass() != obj.getClass()) 066 return false; 067 068 FastPowersetState<?> other = (FastPowersetState<?>) obj; 069 return bs.equals(other.bs); 070 } 071 072 073 074 075}