nodit icon indicating copy to clipboard operation
nodit copied to clipboard

Add a method to insert, overwriting the interval and merging if touching values are equal.

Open ChocolateLoverRaj opened this issue 7 months ago • 2 comments

So let's say I want to insert B at 1..=1: AAA -> ABA BAB -> BBB AAB -> ABB

I am using a nodit map to keep track of physical memory in my OS. When I allocate memory I find an unused interval and then I want to mark that interval as used. The problem with insert_overwrite is that it does not merge with equal intervals before or after it, leading to the size of the NoditMap always increasing when it could be smaller because of merging.

The workaround is to use cut and then insert_merge_touching_if_values_equal, but it would be more convenient if there was a single method for this (and I think maybe it would be more performant too).

ChocolateLoverRaj avatar Jun 08 '25 05:06 ChocolateLoverRaj

So you'd like a method called insert_merge_touching_or_overlapping_if_values_equal()? Bit of a mouthful, but it sounds like a valid usecase.

My one question is why you need to use cut() in your workaround, if the interval you are inserting is unused then is it not present in the map and hence cutting it would do nothing? Perhaps you are using an always-occupied map by using some sort of occupied/not-occupied enum like:

type MemoryMap = NoditMap<usize, RangeInclusive<usize>, MemoryAllocation>;

enum MemoryAllocation {
    Allocated(...),
    Unallocated,
}

ripytide avatar Jun 08 '25 10:06 ripytide

Yeah, I set the usable interval to a Usable enum variant to keep track of usable physical memory. There are some empty parts of the map, but those parts of memory cannot be used.

ChocolateLoverRaj avatar Jun 08 '25 18:06 ChocolateLoverRaj