-
Notifications
You must be signed in to change notification settings - Fork 8
Implements missing functions firstKey / nextKey / exists #1
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,9 @@ class PHP extends Reader { | |
| /* initialized if cdb_findnext() returns 1 */ | ||
| protected $dlen; | ||
|
|
||
| /* initialized in firstkey() and nextkey() */ | ||
| protected $pos = 0; | ||
|
|
||
| /** | ||
| * @param string $fileName | ||
| * @throws Exception | ||
|
|
@@ -217,5 +220,29 @@ protected function find( $key ) { | |
|
|
||
| return $this->findNext( $key ); | ||
| } | ||
|
|
||
| public function exists( $key ) { | ||
| if ( $this->find( strval( $key ) ) ) { | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| public function firstkey() { | ||
| $buf = $this->read( 8, 2048 ); | ||
| $klen = $this->unpackSigned( substr( $buf, 0, 4 ) ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unpack31() |
||
| $dlen = $this->unpackSigned( substr( $buf, 4 ) ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unpack31() |
||
| $this->pos = 2048 + 4 + 4 + $klen + $dlen; | ||
| return fread( $this->handle, $klen ); | ||
| } | ||
|
|
||
| public function nextkey() { | ||
| $buf = $this->read( 8, $this->pos ); | ||
| $klen = $this->unpackSigned( substr( $buf, 0, 4 ) ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unpack31() |
||
| $dlen = $this->unpackSigned( substr( $buf, 4 ) ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unpack31() |
||
| $this->pos += 8 + $klen + $dlen; | ||
| return fread( $this->handle, $klen ); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your implementation is basically a transliteration of the PHP 5.3 implementation, but you could reduce duplication by having
firstKey()set$this->pos = 2048and then return$this->nextKey().