What is the most efficient data structure for storing a list of integers that you need to search a lot in .Net?

I need an efficient data structure to store a list of integers. The amount in the list can vary from 1 to probably not more than 1000. The list will be requested approximately 20 times per request. What would be the most efficient type of collection to store?

UPDATE

To give a little more information, we'll take www.wikipediamaze.com (the little game I wrote) as an example (not a real scenario, but close enough for a conversation). For the list of puzzles on any given page, I am currently returning a list from the puzzle table connected to the table in which the puzzles that the current user played are stored. Instead, I want to cache a list of puzzles that are independent of the user. So what I'm doing is the first load and cache the list of puzzles from the database. Then I load and cache the list of puzzles that the user played. Then, when I repeat the puzzles to display them, I want to do this:

protected BestDataStructure<long> PlayedPuzzles {get; set;} //Loaded from session

protected bool HasBeenPlayed(long puzzleId)
{
    return PlayedPuzzles.Contains(puzzleId)
}

, , , .

!

+3
4

, , , HashSet<int>, .

O (1), . HashSet.Contains O (1).

: HashSet, , . Contains() HashSet; . , , , .

+5

, ​​, Contains(), HashSet<int> - , . HashSet<int> - O (1) ( ) Contains(), , .

+2
+1
source

if you need to check for an element and then probably bool[]with 1000 elements and set true for existing integer elements?

+1
source

Source: https://habr.com/ru/post/1760136/


All Articles