306
307
308
309
310
311
312
313
314
|
}
proc ::xvfs::staticIncludeHeader {pathToHeaderFile} {
set fd [open $pathToHeaderFile]
::xvfs::staticIncludeHeaderData [read $fd]
close $fd
}
package provide xvfs 1
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
}
proc ::xvfs::staticIncludeHeader {pathToHeaderFile} {
set fd [open $pathToHeaderFile]
::xvfs::staticIncludeHeaderData [read $fd]
close $fd
}
proc ::xvfs::generatePerfectHashFunctionCall {cVarName cVarLength invalidValue nameList} {
set minVal 0
set maxVal [llength $nameList]
set testExpr {([zlib adler32 $nameItem $alpha] + $beta) % $gamma}
set testExprC {((Tcl_ZlibAdler32($alpha, (unsigned char *) $cVarName, $cVarLength) + $beta) % $gamma)}
set round -1
set beta 0
set gamma $maxVal
while true {
incr round
set alpha $round
set gamma [expr {($round % ($maxVal + 1)) + $maxVal}]
set idx -1
set seenIndexes [list]
set failed false
foreach nameItem $nameList {
incr idx
set testExprVal [expr $testExpr]
if {$testExprVal in $seenIndexes} {
incr alpha
set failed true
break
}
lappend seenIndexes $testExprVal
}
if {!$failed} {
break
}
}
unset -nocomplain mapArray
for {set idx 0} {$idx < $gamma} {incr idx} {
set mapArray($idx) $invalidValue
}
set idx -1
foreach nameItem $nameList {
incr idx
set mapArray([expr $testExpr]) $idx
}
set map "(long\[\])\{"
for {set idx 0} {$idx < $gamma} {incr idx} {
append map "$mapArray($idx), "
}
set map [string range $map 0 end-2]
append map "\}\[[subst $testExprC]\]"
set phfCall $map
return $phfCall
}
package provide xvfs 1
|