title: Choosing data strucutures to sort TOP 10 items out of zillion items based on users rating
body: <p>Lets say you're running a movie database website like IMDb/Netflix and users rate each movie from 1-10 star. When a user rate movie, I get id (long) and rating from 1-10 in the request. The Movie class looks like this.</p>
  
  <pre><code>class Movie
  {
      long id;
      String name;
      double avgRating;     //Avg Rating of this movie
      long numberOfRatings; //how many times this movie was rated.
  }
  
  public void updateRating(long movieId, int rating)
  {
  
      //code to update movie rating and update top 10 movie to show on page.
  }
  </code></pre>
  
  <p>My question is what data structures I can choose to keep huge movies data in memory so that on each updateRating call, i update movie rating as well as update Top 10 movie and reflect on the webpage and users will always see the latest top 10 movies. I have a lot of space on web server and i can keep all the movies objects in memory. The challenges here are 
  <BR/><BR/>
  1) Look up a movie by id.<BR/>
  2) update movie rating.<BR/>
  3) choose new location of this movie in the sorted collection of movies (sorted by ratings)
  and if its new position is in first top 10, show it on web page.<BR/>
  <BR/><BR/>
  All these operations should be done in best optimal time. </p>
  
  <p><I>this is not a homework but a general programming and data structure question.</I></p>