Skip to content

Commit

Permalink
[skip ci] revert maptofactory
Browse files Browse the repository at this point in the history
  • Loading branch information
Baunsgaard committed Jan 21, 2025
1 parent e2afaa9 commit 64ce453
Showing 1 changed file with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,21 @@ public static AMapToData create(int unique, IntArrayList values) {
return _data;
}

public static AMapToData create(int size, int[] values, int nUnique, int k) {
public static AMapToData create(int size, int[] values, int nUnique, int k) throws Exception {
AMapToData _data = create(size, nUnique);
final ExecutorService pool = CommonThreadPool.get(k);
try{

AMapToData _data = create(size, nUnique);
int blk = Math.max((values.length / k), 1024);
blk -= blk % 64; // ensure long size
List<Future<?>> tasks = new ArrayList<>();
for(int i = 0; i < values.length; i += blk) {
int start = i;
int end = Math.min(i + blk, values.length);
tasks.add(pool.submit(() -> _data.copyInt(values, start, end)));
}

for(Future<?> t : tasks)
t.get();
return _data;
}
catch(Exception e){
throw new RuntimeException();
}
finally{
pool.shutdown();
int blk = Math.max((values.length / k), 1024);
blk -= blk % 64; // ensure long size
List<Future<?>> tasks = new ArrayList<>();
for(int i = 0; i < values.length; i += blk) {
int start = i;
int end = Math.min(i + blk, values.length);
tasks.add(pool.submit(() -> _data.copyInt(values, start, end)));
}

for(Future<?> t : tasks)
t.get();
return _data;
}

/**
Expand Down

0 comments on commit 64ce453

Please sign in to comment.