Skip to content

A Java library that produces all word permutations at variable lengths for given alphabets in a distributed manner such that produced words can then be used by multiple consumer threads concurrently.

License

Notifications You must be signed in to change notification settings

ender-s/WordProducer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

WordProducer

A Java library that produces all word permutations at variable lengths for given alphabets in a distributed manner such that produced words can then be used by multiple consumer threads concurrently.

Sample Usage

import java.util.List;
import java.util.concurrent.*;
import java.util.stream.Collectors;

import enders.wordproducer.manager.WordProducerManager;

public class Main {
    public static void main(String[] args) {
        List<String> symbolList = "abc0123"
                .chars()
                .mapToObj(e -> String.valueOf((char) e))
                .collect(Collectors.toList());

        WordProducerManager wpm = new WordProducerManager.Builder()
                .setNumberOfQueues(3)
                .setThreadsPerQueueAuto()
                .putSymbolsToRange(1, 4, symbolList)
                .build();

        List<BlockingQueue<String>> queues = wpm.produce();
        ExecutorService es = Executors.newFixedThreadPool(queues.size());
        for (BlockingQueue<String> q : queues) {
            es.execute(() -> {
                while (!wpm.isCompleted()) {
                    try {
                        String word = q.poll(100, TimeUnit.MILLISECONDS);
                        if (word != null) {
                            System.out.println(word);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        es.shutdown();
    }
}

About

A Java library that produces all word permutations at variable lengths for given alphabets in a distributed manner such that produced words can then be used by multiple consumer threads concurrently.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages