C#
C#

help

Root Question Message

Deaths Angel
Deaths Angel12/14/2022
❔ How do I search through a list for the first missing value in a range of numbers?

For instance; a list of 0, 1, 2, 4, 5, 6, 7, 9 would return 3 if you're looking for the first "missing" value.
Likewise, a list of 1, 2, 4, 5, 6, 7, 9 would return 0.
Angius
Angius12/14/2022
Create a list that contains the full sequence, then iterate over those two lists at once
Angius
Angius12/14/2022
Check if the items match, and return the first one that's not matching
Deaths Angel
Deaths Angel12/14/2022
Yeah, but I would need it to use 3 separate ranges of numbers, and I'm trying to keep it as skinny as possible, if at all possible.
Angius
Angius12/14/2022
Why 3?
Angius
Angius12/14/2022
Two
Angius
Angius12/14/2022
The list you're checking, and the list you're checking against
Angius
Angius12/14/2022
Alternatively, you can of course check if n+1 - 1 == 1
Deaths Angel
Deaths Angel12/14/2022
I'm basically making a new ID, and I want it to take the first value that's free so I can use that, rather than just adding 1 to the end of the list(which will be what happens if I don't find anything). I have 3 separate ranges of numbers that would need to be checked, depending on a value that's passed in. Does that make more sense? I know I'm not explaining the best.
Deaths Angel
Deaths Angel12/14/2022
Also these lists are around 100 million long, so making that separate full list would be pretty impractical. 😅
Angius
Angius12/14/2022
I wouldn't worry about taking up every possible ID, then, to be honest
Angius
Angius12/14/2022
No database engine does
Angius
Angius12/14/2022
They just keep track of the last ID and insert the next item at that plus one
Deaths Angel
Deaths Angel12/14/2022
Yeah, that's fair. I was just trying to save as much space as possible, I guess. Though, I doubt anyone will hit 100 million items in one database.
Deaths Angel
Deaths Angel12/14/2022
Thanks for the help!
AntonC
AntonC12/14/2022
check out free lists some time
Deaths Angel
Deaths Angel12/14/2022
Do you have a link?
AntonC
AntonC12/14/2022
the id stuff is captured in this blog https://skypjack.github.io/2019-02-14-ecs-baf-part-1/
Deaths Angel
Deaths Angel12/14/2022
Ok, I'll take a look in a little bit. Thanks!
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy