Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/freddiehaddad/rnti
Multithreaded Roman Numeral to Integer converter written in Go.
https://github.com/freddiehaddad/rnti
concurrency concurrent-programming go golang leetcode leetcode-go leetcode-golang leetcode-solution multithreading
Last synced: 16 days ago
JSON representation
Multithreaded Roman Numeral to Integer converter written in Go.
- Host: GitHub
- URL: https://github.com/freddiehaddad/rnti
- Owner: freddiehaddad
- Created: 2024-02-10T06:32:08.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2024-02-12T15:24:45.000Z (12 months ago)
- Last Synced: 2025-01-03T03:48:43.415Z (24 days ago)
- Topics: concurrency, concurrent-programming, go, golang, leetcode, leetcode-go, leetcode-golang, leetcode-solution, multithreading
- Language: Go
- Homepage: https://leetcode.com/problems/roman-to-integer/description/?envType=study-plan-v2&envId=top-interview-150
- Size: 2.93 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Multithreaded Roman Numeral to Integer Converter
Program to convert a Roman Numeral string to an integer using using channels and
concurrency.The program works by spawning three threads with specific responsibilities:
- Read lexical values from a Roman Numeral string
- Look up numeric value for each lexeme
- Sum the numeric valuesData is fed from one Go routine to the next using independent channels.
`readSymbols` parses the input string creating tokens and sending them to
`readValues` over a channel. Within `readValues` each token is converted to a
numeric value using an internal map and sent to `addValues` using a channel.
`addValues` sums the values and sends the result to another channel. Convert
blocks until a value is received and returns that value.Note: `readValues` creates a Go routine for each roman numeral that handles the
conversion to an integer. Thus the order in which values are summed in
`addValues` is asynchronous. Refer to the function itself or `TestReadSymbols`
for more details.```text
+-------------------------+
| "MCMXCIV" G |
| |
| |
| Convert() |
+--+----------------------+
|
| +--------------------------+ +--------------------------+
| | "MCMXCIV" G | | [M, CM, XC, ...] G |
| | | | |
+------->| +------->| |
| readSymbols() | | readValues() |
+--------------------------+ +-------------+------------+
|
v
+-------------+------------+ +--------------------------+
| [1000 + 900 + ...] G | | "CM" G |-+
| | | | |-+
| |<-------------+ | | |
| addValues() | | anonymous() | | |
+--------------------------+ +--------------------------+ | |
+--------------------------+ |
+--------------------------+G: Go Routine
```