Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
shrink conditional in removeDA and removes in CDA
#1
I'm curious if the conditional test I am using for the remove methods is correct. Currently I am using 0.25 > size / capacity, and converting them to doubles so that the division is 
more precise. (By typecasting double to the numerator). Is there a better way of computing this? 

I'm adding 9 values, going up to a capacity 16 array. Then I remove all but 1, and only go down to a capacity 8 array. I remove the final value, shrinking to capacity 4. I add a value, staying at capacity 4. Then remove the final value, staying at 4. I'm not shrinking when the ratio is less than .25 and i believe my conditional test is the culprit.

Also in a slightly related note, when using wget on the da-test-0-3.c file I only get the code for part of this test, mainly just the inserts. Do these just act as sample tests and we must fill out the rest?
Reply
#2
When do you subtract the size from the structure? Do you do it before the conditional or after? I had a similar issue and i was subtracting after my if statement so i ended up making my conditional similar to yours but I have size-1.
Reply
#3
(09-11-2017, 12:44 PM)smmitchell2 Wrote: When do you subtract the size from the structure? Do you do it before the conditional or after? I had a similar issue and i was subtracting after my if statement so i ended up making my conditional similar to yours but I have size-1.

I'm doing it before now, on all my insert and remove methods (for increasing or decreasing size). And it seems to have fixed my code. But before I was doing it after, before the return.
I am still using size rather than size-1 in my conditional statements, which is okay I think because I moved when I was changing the size value from after the conditional to before. Please let me know if this sounds right.
Reply
#4
I tried subtracting my struc->size before and on some cases it messed up capacity dramatically. Have you tested with all the test files to see if they all work?
Reply
#5
(09-11-2017, 01:29 PM)smmitchell2 Wrote: I tried subtracting my struc->size before and on some cases it messed up capacity dramatically. Have you tested with all the test files to see if they all work?

I'm currently working on running all of the tests available to me against my new code. As a general rule I use grow condition before adding in insert, and use shrink condition after removing in remove. I think this fits the spec. This seems to work fine on my personal tests and against his test dropbox, I am working on getting the 35 tests to run against it.
Reply
#6
(09-13-2017, 02:38 PM)ianbway Wrote:
(09-11-2017, 01:29 PM)smmitchell2 Wrote: I tried subtracting my struc->size before and on some cases it messed up capacity dramatically. Have you tested with all the test files to see if they all work?

I'm currently working on running all of the tests available to me against my new code. As a general rule I use grow condition before adding in insert, and use shrink condition after removing in remove. I think this fits the spec. This seems to work fine on my personal tests and against his test dropbox, I am working on getting the 35 tests to run against it.

The tests run against it and produce the correct results. The exception would be the four tests that use the custom string class, which I do not have. But I passed those tests on the last submission so I assume they work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)