Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 308961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:41:54+00:00 2026-05-12T07:41:54+00:00

I need a CircularBuffer IDictionary. Can anyone point me to a good open source

  • 0

I need a CircularBuffer IDictionary. Can anyone point me to a good open source implementation.

So a IDictionary that has a maximum capacity, say configured to 100 items, which when item 101 is added the original first item is popped/removed from the dictionary thus ensuring the item count never exceeds 100.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:41:54+00:00Added an answer on May 12, 2026 at 7:41 am

    To keep O(1) insertion (with removal of the oldest item past 100) and O(1) lookups, you’ll need a class that implements IDictionary and keeps an internal ordered list. If memory is more a concern, a BST implementation like SortedList could be more appropriate. Anyway, your class will contain both a T[] and a Dictionary<T,K> (or SortedList<T,K>). Do your own circular buffer indexing (easy), and keep both collections current in the add, remove, etc. methods. You’ll have:

    • O(1) enqueue (to back)
    • O(n) insertion that violates order of adding (since you have to keep the array up to date); you’ll likely never need this anyway
    • O(1) dequeue (from front)
    • O(1) or O(log n) keyed lookup

    Make it generic and implement IDictionary<T,K> and IDictionary since there’s no reason not to and you’ll get an edge in performance.

    One major consideration: what do you do about duplicate keys? I’m assuming you can’t actually keep the duplicates, so:

    • Throw an exception (if there are never duplicate keys, so it’s simply an error to insert something twice)
    • Move to back: check the Count of the dictionary, then insert the key using the this[key] indexer. if the size increases, then check if the list already has the maximum capacity, remove the front item from the list and dictionary and add the new item to the back. If the dictionary did not increase in size, move the item from its existing place in the list to the back of the list.
    • Overwrite without moving: The same as the previous item, but you don’t have to mess with the list.

    Finally, note that the internal list keeps keys, not values. This is to ensure O(1) dequeue when the list capacity is exceeded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 173k
  • Answers 173k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try this: <asp:ImageButton ID="btnChangeMedium" OnClick="Change_Click" runat="server" OnClientClick="javascript:void(0);ChangeMedium();"/> May 12, 2026 at 2:36 pm
  • Editorial Team
    Editorial Team added an answer Just pass it through locals like in your second example… May 12, 2026 at 2:36 pm
  • Editorial Team
    Editorial Team added an answer With Notepad++, you can show end-of-line characters. It shows CR… May 12, 2026 at 2:36 pm

Related Questions

I have a need for a fixed-size (selectable at run-time when creating it, not
I want a simple class that implements a fixed-size circular buffer . It should
I have a C application with many worker threads. It is essential that these
I need a C# profiler. Although I'm not averse to paying for one, something

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.