Skip to content

youngwan657/vote

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reddit service

How to build

git clone https://github.com/tiny657/vote
cd vote
./gradlew clean build

How to start

./start.sh

How to stop

./stop.sh

Demo server

Screenshot

API specifications

Show a list of top 20 topics

GET /v1/reddit/topics?top20&orderBy=popularity

Show form

GET /v1/reddit/topics/new

Register topic

POST /v1/reddit/topics

{"text": "...."}

Upvote

POST /v1/reddit/topics/{topicId}/up

Downvote

POST /v1/reddit/topics/{topicId}/down

Data structures

  1. ConcurrentHashMap<topicId, Topic>: All topics are stored. This map is thread-safe.
  2. max-heap: To sort by upvotes in descending order, I will use max-heap.
  3. List: To speed up showing top 20, this list is created like a cache.

Algorithms

  • When a new topic is submitted, the code works as follows.

    1. An AtomicInteger generated globally unique topic id.
    2. The new topic is stored in the ConcurrentHashMap.
    3. The new topic is also stored in the max-heap.
    4. Top 20 list is refreshed to cache top 20 from max-heap.
  • When UP is clicked, the code works as follows.

    1. The upvote count in a topic is increased.
    2. Max-heap is refreshed to consider the topic which the upvote count is changed.
    3. Top 20 list is refreshed from changed max-heap.
  • When DOWN is clicked, the code works as follows.

    1. The downvote count in a topic is increased.
    2. We do not need to refresh the max-heap and top 20 list because top 20 is only considered upvote count.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published