dchen23 / PrimeNumbersCalculator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PrimeNumbersCalculator

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

Environment

  • Android Studio Hedgehog | 2023.1.1 Canary 16
    • NDK 25.1.8937393
    • cmake 3.22.1
  • Test Device: OnePlus 7 Pro (Android 11)

Usage

main ui

  1. 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 !

  2. Click the RUN button to calculate all prime numbers;
  3. 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;
  4. The result of N:th prime numbers will display on the OUTPUT textview;
  5. Click the CLR buttorn, both the INPUT text box and OUTPUT textview will reset;
  6. 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
    

Documentation

The core cross-plarform library can be delievered as .so/.h files:

The functionality can be divided into four main parts:

  1. Numeric Sequence Pharser: Use regex to find all matched numeric inputs
  2. Prime Calculator: A brute force approaching to find N:th prime number is less than or equal to 50,000 in order
  3. C-style API Wrapper: A C API layer provides better compatibility and interoperability, while also avoiding C++ feature conflicts and ensuring API stability
  4. Thread Pool Utility: A thread pool manages a fixed set of threads, improving resource utilizaion and enbaling efficient concurrent task execution
  5. 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
  6. Android App: A Kotlin frontend can communicate with native libraries using the Java Native Interface (JNI).

Achievements

  • 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.

Screenshots

1. Display result on output textview

main ui

2. Buttons are unclickable during calculation

main ui

3. Each workflow process in a threaded operation, different tid under same pid

main ui

4. Threads are released when UI is inactive.

main ui

TODO

  • 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.

About

License:MIT License


Languages

Language:C++ 56.1%Language:Kotlin 33.2%Language:CMake 10.7%