nsmcp::BoundedLogScanner method find (public)

 <instance of nsmcp::BoundedLogScanner[i]> find from [ ceiling ]

Defined in /usr/local/ns/tcl/nsmcp/log-01-scanner.tcl

Parameters:
from (required)
ceiling (optional)

Testcases:
No testcase defined.
Source code:
if {$ceiling eq ""} {set ceiling ${:limit}}
if {![string is entier -strict $from] || ![string is entier -strict $ceiling]
    || $from<0 || $ceiling<$from || $ceiling>${:limit}} {error "invalid scanner byte interval"}
set position $from
while {$position<$ceiling} {
    if {${:channel} eq ""} {
        set found [:first $position $ceiling]
        if {$found>=0} {incr :windowHits}
        return $found
    }
    if {$position<${:bufferFrom} || $position>=${:bufferEnd} || ${:windowCeiling}!=$ceiling} {
        seek ${:channel} $position
        set expected [expr {min(${:readBytes},$ceiling-$position)}]
        set bytes [read ${:channel} $expected]
        if {[string length $bytes]<$expected} {error "source ended before its fixed scanner bound"}
        :setBuffer $bytes $position $ceiling
    }
    set found [:first $position [expr {min($ceiling,${:bufferEnd})}]]
    # A short batch key near the end cannot win before a longer key
    # beginning earlier but crossing this boundary has been checked.
    if {$found>=0 && (${:bufferEnd}>=$ceiling || $found<${:bufferEnd}-${:overlap})} {incr :windowHits; return $found}
    if {${:bufferEnd}>=$ceiling} {return -1}
    if {${:windowHits}==0} {
        set :readBytes [expr {min(${:blockBytes},2*${:readBytes})}]
    } else {
        set :readBytes [expr {min(${:blockBytes},65536)}]
    }
    set position [expr {max($from,${:bufferEnd}-${:overlap})}]
    # Refill even though the overlap is inside the previous buffer.
    set :windowCeiling -1
}
return -1
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: