A cross-platform library and an Android app that can calculate the N:th prime number based on user input.
APK: Download
adb install app-debug.apk
- Android Studio Hedgehog | 2023.1.1 Canary 16
- NDK 25.1.8937393
- cmake 3.22.1
- Test Device: OnePlus 7 Pro (Android 11)
- Type anything you like inside
INPUT
text box;NOTE: Only intergers in range (0, 50000] will return proper result, non-calculable input will always return
0
! - Click the
RUN
button to calculate all prime numbers; - If input sequence has large value (like 20,000), the process will take longer, and all button will be unclickable. Just wait for few seconds;
- The result of N:th prime numbers will display on the
OUTPUT
textview; - Click the
CLR
buttorn, both theINPUT
text box andOUTPUT
textview will reset; - Start forn 1st step.
The Examples of Input/Ouput
- Sample Input #1
Hello 2, 4, 7.5
- Sample Output #1
3, 7, 17
- Sample Input #2
0 1 -10 +34.5 12000
- Sample Output #2
0, 2, 0, 139, 128189
- Sample Input #3
-+abc123 #$-345 7 "!$+50000 50001
- Sample Output #3
677, 0, 17, 611953, 0
The core cross-plarform library can be delievered as .so/.h files:
- PrimeNumbersAPI.so: PrimeNumbersAPI.cpp, prime.cpp, prime.h, threadpool.h
- PrimeNumbersAPI.h: PrimeNumbersAPI.h.
The functionality can be divided into four main parts:
- Numeric Sequence Pharser: Use regex to find all matched numeric inputs
- Prime Calculator: A brute force approaching to find N:th prime number is less than or equal to 50,000 in order
- C-style API Wrapper: A C API layer provides better compatibility and interoperability, while also avoiding C++ feature conflicts and ensuring API stability
- Thread Pool Utility: A thread pool manages a fixed set of threads, improving resource utilizaion and enbaling efficient concurrent task execution
- Hybird Lifetime Control: An objects and resources manager for both Kotlin and C++ languages, considering their distinct memory management and lifetime paradigms within a single application
- Android App: A Kotlin frontend can communicate with native libraries using the Java Native Interface (JNI).
- Application responsiveness & edge cases
- Cross platform compatibility
- Multithreading support
- Memory management
- Library API design
- Code readability
- Threads/resources should be properly terminated/released after UI has been closed.
- Utilize a hash table to store calculated
order, prime_number
pairs - Apply less time-consuming prime number calculation algorithm, like Sieve of Eratosthenes or Sieve of Atkin
- Support more numeric input format, such as scientific notation, arithmetic calculation and so on
- Change application frontend to compose UI framework.