shrink conditional in removeDA and removes in CDA - Printable Version +- The Beastie Forums (http://beastie.cs.ua.edu/mybb) +-- Forum: Analysis of Algorithms (http://beastie.cs.ua.edu/mybb/forumdisplay.php?fid=3) +--- Forum: Project 0 (http://beastie.cs.ua.edu/mybb/forumdisplay.php?fid=4) +--- Thread: shrink conditional in removeDA and removes in CDA (/showthread.php?tid=173) shrink conditional in removeDA and removes in CDA - ianbway - 09-10-2017 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? RE: shrink conditional in removeDA and removes in CDA - smmitchell2 - 09-11-2017 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. RE: shrink conditional in removeDA and removes in CDA - ianbway - 09-11-2017 (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. RE: shrink conditional in removeDA and removes in CDA - smmitchell2 - 09-11-2017 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? RE: shrink conditional in removeDA and removes in CDA - ianbway - 09-13-2017 (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. RE: shrink conditional in removeDA and removes in CDA - ianbway - 09-14-2017 (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.