Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/freddiehaddad/palindrome

Multithreaded palindrome detector written in Go.
https://github.com/freddiehaddad/palindrome

concurrency concurrent-programming go golang leetcode leetcode-go leetcode-golang leetcode-solution multithreading

Last synced: about 1 month ago
JSON representation

Multithreaded palindrome detector written in Go.

Awesome Lists containing this project

README

        

# Multithreaded Palindrome Detector

Program to check if a string is a palindrome using channels and concurrency.

The program works by spawning three threads with specific responsibilities. One
thread reads characters starting from the left and feeds palindrome characters
to a unique channel. The second thread reads characters from the right also
feeding palindrome characters to another unique channel. The third thread reads
characters from these two channels and compares them until the indices cross or
two non-matching characters are encountered and reports the result of comparing
to another separate channel.

Palindrome characters are alphanumeric. Anything else is ignored. For example,
in the string `"A man, a plan, a canal: Panama"`, the spaces, commas and the
colon are ignored and the palindrome comparison occurs as if the string was
`"amanaplanacanalpanama"`.

Also note that the strings are case insensitive.

```text
+-------------------------+
| "Madam, I'm Adam" G |
| |
| +--+---------------------+
| isPalindrome() | | |
+--+----------------------+ | |
| v v
| +--------------------------+ +--------------------------+
| | "Madam, I" G | | "I'm Adam" G |
| | | | |
| | | | |
| | feedCharactersForward() | | feedCharactersReverse() |
| +----+---------------------+ +-------------+------------+
| | |
| | +-------------------------+
| | |
| v v
| +--------------------------+
| | "madami" "madami" G |
| | |
+-->| |
| compareCharacters() |
+--------------------------+

G: Go Routine
```