Re: array_unique and some questions on Zend hash internals

From: Date: Sun, 04 Jun 2000 13:46:13 +0000
Subject: Re: array_unique and some questions on Zend hash internals
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-20178@lists.php.net to get a copy of this message
On Sun, 04 Jun 2000, Stig Venaas wrote: > array_data_compare returns 0 if compare_function fails (one of the > operators being an object or array), this means that array_unique will > remove arrays and objects from the array in most cases. Ideally this > shouldn't happen, is there a better way than using compare_function > directly and duplicate most of the code from array_data_compare? Perhaps > I shouldn't bother, at least I can live with this "feature". Hi. You shouldn't be accessing Buckets directly. Instead, utilize the zend_hash_* functions to traverse the array and copy only unique values into a new array. Then if you want, you can replace the contents of the original with the new one. > | lastkept = cmpdata; > | } else { > | /* should use zend_hash_apply_deleter() from API */ > | my_hash_apply_deleter(target_hash, *cmpdata); > > I want to use zend_hash_apply_deleter here, it will be quicker than finding > the bucket from the key, but the deleter function isn't part of the Zend API. > If I am to use it I have to either expose it (you probably don't want any > functions with Bucket arguments in the API), or add a function > zend_hash_unique to the API. Do you see any better way? You won't need hash deleter if you follow above advice. > One last thing, if I have an array indexed by numbers, say > array("a", "a", "b"), array_unique would change it into > array("a", 2 => "b"). Do you think it should be array("a", > "b")? > What is the best way of doing this? The second way. Since you're eliminating array values, it won't really matter what the keys are since it might be implementation dependant. -Andrei

« previous php.dev (#20178) next »