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.words.impl; 018 019import java.util.Arrays; 020import java.util.List; 021 022import net.automatalib.commons.util.nid.DynamicList; 023import net.automatalib.commons.util.nid.MutableNumericID; 024import net.automatalib.words.GrowingAlphabet; 025 026/** 027 * A fast alphabet implementation, that assumes identifiers are stored directly in the 028 * input symbols. 029 * 030 * @author Malte Isberner <malte.isberner@cs.uni-dortmund.de> 031 * 032 * @param <I> input symbol class. 033 */ 034public class FastAlphabet<I extends MutableNumericID> extends DynamicList<I> 035 implements GrowingAlphabet<I> { 036 037 038 public FastAlphabet() { 039 040 } 041 042 public FastAlphabet(List<? extends I> symbols) { 043 for(I sym : symbols) 044 addSymbol(sym); 045 } 046 047 @SafeVarargs 048 public FastAlphabet(I ...symbols) { 049 this(Arrays.asList(symbols)); 050 } 051 /* 052 * (non-Javadoc) 053 * @see de.ls5.words.Alphabet#getSymbol(int) 054 */ 055 @Override 056 public I getSymbol(int index) { 057 return get(index); 058 } 059 060 /* 061 * (non-Javadoc) 062 * @see de.ls5.words.Alphabet#getSymbolIndex(java.lang.Object) 063 */ 064 @Override 065 public int getSymbolIndex(I symbol) { 066 return symbol.getId(); 067 } 068 069 /* 070 * (non-Javadoc) 071 * @see de.ls5.words.GrowingAlphabet#addSymbol(java.lang.Object) 072 */ 073 @Override 074 public int addSymbol(I a) { 075 add(a); 076 return a.getId(); 077 } 078 079 @Override 080 public int compare(I o1, I o2) { 081 return o1.getId() - o2.getId(); 082 } 083 084 085}