Re: array_unique and some questions on Zend hash internals

From: Date: Wed, 07 Jun 2000 21:25:55 +0000
Subject: Re: array_unique and some questions on Zend hash internals
References: 1 2 3 4 5  Groups: php.dev 
Request: Send a blank email to php-dev+get-20514@lists.php.net to get a copy of this message
On Wed, 07 Jun 2000, Stig Venaas wrote: > I see two ways, one is to insert everything in a new hash like in splice, > or as below (as in for instance zend_hash_sort) > > for ( i = 0, p = ht->pListHead; p; p = p->pListNext) > if (!p->nKeyLength) > p->h = i++; > ht->nNextFreeElement = i; > zend_hash_rehash(ht); > > I think this is a little faster, especially when most elements have > keys rather than indices, but you know the code better than me. > Think perhaps it's possible to write a quicker renumbering routine by > using the hash internals directly, which is a bit nasty. Well, you'll have to decide whether to preserve or compact numeric keys always, or let the user decide. Personally, I wouldn't have the need for compacting numeric keys, but that's just me. > Here's my new array_unique function, what do you think? I'm still using > buckets slightly, do you want me to avoid it completely? If so, is there > a better way than copying the entire hash and sorting with zend_hash_sort? > If you like it, I can add it to CVS myself. I don't see many people posting > patches, would you prefer if I submitted things some other way? BTW, I'm > still wondering where/when I should use BLOCK/UNBLOCK. Well, if you leave it using buckets, then you're bypassing the API and you are relying on the internal hash representation to not change in the future. It's your call. BLOCK/UNBLOCK should be using around code that should be interrupted during multi-threaded execution (like modifying buckets in the hash). Currently no SAPI module provides sapi_block_interruptions routine. -Andrei 'Any given program, when running correctly, is obsolete.' - First Law of Computer Programming

« previous php.dev (#20514) next »