diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/database/ids/integer/TrivialDBIDFactory.java')
-rw-r--r-- | src/de/lmu/ifi/dbs/elki/database/ids/integer/TrivialDBIDFactory.java | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/database/ids/integer/TrivialDBIDFactory.java b/src/de/lmu/ifi/dbs/elki/database/ids/integer/TrivialDBIDFactory.java index 577c29ac..cc5f6add 100644 --- a/src/de/lmu/ifi/dbs/elki/database/ids/integer/TrivialDBIDFactory.java +++ b/src/de/lmu/ifi/dbs/elki/database/ids/integer/TrivialDBIDFactory.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.database.ids.integer; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2013 + Copyright (C) 2014 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -55,7 +55,7 @@ final public class TrivialDBIDFactory extends AbstractIntegerDBIDFactory { @Override final public DBID generateSingleDBID() { final int id = next.getAndIncrement(); - if (id == Integer.MAX_VALUE) { + if(id == Integer.MAX_VALUE) { throw new AbortException("DBID allocation error - too many objects allocated!"); } DBID ret = new IntegerDBID(id); @@ -70,7 +70,7 @@ final public class TrivialDBIDFactory extends AbstractIntegerDBIDFactory { @Override final public DBIDRange generateStaticDBIDRange(int size) { final int start = next.getAndAdd(size); - if (start > next.get()) { + if(start > next.get()) { throw new AbortException("DBID range allocation error - too many objects allocated!"); } DBIDRange alloc = new IntegerDBIDRange(start, size); @@ -78,6 +78,22 @@ final public class TrivialDBIDFactory extends AbstractIntegerDBIDFactory { } @Override + public DBIDRange generateStaticDBIDRange(int begin, int size) { + final int end = begin + size; + if(end > Integer.MAX_VALUE) { + throw new AbortException("DBID range allocation error - too many objects allocated!"); + } + DBIDRange alloc = new IntegerDBIDRange(begin, size); + int v; + while((v = next.get()) < end) { + if(next.compareAndSet(v, end)) { + break; + } + } + return alloc; + } + + @Override public void deallocateDBIDRange(DBIDRange range) { // ignore. } |