Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In chapter 9, Set_union(s,NULL) clones a set.Its member size is smaller than expected #8

Open
GoogleCodeExporter opened this issue Mar 23, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
In CII's chapter 9, Set_union(s,NULL) clones a set, but the cloned set's size 
is smaller.

   Here is test code:

   Set_T s,t;
   s = Set_new(1024,NULL,NULL);
   t = Set_union(s,NULL);
   printf("s:%d, t:%d\n", s->size,t->size);    

   output is: 
   s:1021, t:509 

   The problem seems related to Set_new's implementation:
        static int primes[] = { 509, 509, 1021, 2053, 4093,
                8191, 16381, 32771, 65521, INT_MAX };
        assert(hint >= 0);
        for (i = 1; primes[i] < hint; i++)
                ;

   When giving it a hint, it searches the primes table and use the greatest one less than hint.
   If  the hint happens to be the number in primes, a much less value will be used.

What is the expected output? What do you see instead?
   When clone a set, it's member size should be the same.

What version of the product are you using? On what operating system?
 N/A

Please provide any additional information below.
 N/A

Original issue reported on code.google.com by [email protected] on 27 Jun 2012 at 12:46

@ylme
Copy link

ylme commented Oct 14, 2019

Yeah, so I change primes[i] < hint to primes[i] <= hint. So we will can get the exact value when primes[i] == hint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants