Merge branch 'master' of git://factorcode.org/git/factor
commit
6e2ae41238
|
@ -10,16 +10,17 @@ HELP: <unique-max-heap>
|
||||||
{ $values
|
{ $values
|
||||||
|
|
||||||
{ "unique-heap" assoc-heap } }
|
{ "unique-heap" assoc-heap } }
|
||||||
{ $description "Creates a new " { $link assoc-heap } " where the assoc is a hashtable and the heap is a max-heap." } ;
|
{ $description "Creates a new " { $link assoc-heap } " where the assoc is a hashtable and the heap is a max-heap. Popping an element from the heap leaves this element in the hashtable to ensure that the element will not be processed again." } ;
|
||||||
|
|
||||||
HELP: <unique-min-heap>
|
HELP: <unique-min-heap>
|
||||||
{ $values
|
{ $values
|
||||||
|
|
||||||
{ "unique-heap" assoc-heap } }
|
{ "unique-heap" assoc-heap } }
|
||||||
{ $description "Creates a new " { $link assoc-heap } " where the assoc is a hashtable and the heap is a min-heap." } ;
|
{ $description "Creates a new " { $link assoc-heap } " where the assoc is a hashtable and the heap is a min-heap. Popping an element from the heap leaves this element in the hashtable to ensure that the element will not be processed again." } ;
|
||||||
|
|
||||||
|
{ <unique-max-heap> <unique-min-heap> } related-words
|
||||||
|
|
||||||
HELP: assoc-heap
|
HELP: assoc-heap
|
||||||
{ $description "A data structure containing an assoc and a heap to get certain properties with better time constraints at the expense of more space and complexity. For instance, a hashtable and a heap can be combined into one assoc-heap to get a sorted data structure with O(1) lookup. Operations on assoc-heap should update both the assoc and the heap." } ;
|
{ $description "A data structure containing an assoc and a heap to get certain properties with better time constraints at the expense of more space and complexity. For instance, a hashtable and a heap can be combined into one assoc-heap to get a sorted data structure with O(1) lookup. Operations on assoc-heap may update both the assoc and the heap or leave them out of sync if it's advantageous." } ;
|
||||||
|
|
||||||
ARTICLE: "assoc-heaps" "Associative heaps"
|
ARTICLE: "assoc-heaps" "Associative heaps"
|
||||||
"The " { $vocab-link "assoc-heaps" } " vocabulary combines exists to synthesize data structures with better time properties than either of the two component data structures alone." $nl
|
"The " { $vocab-link "assoc-heaps" } " vocabulary combines exists to synthesize data structures with better time properties than either of the two component data structures alone." $nl
|
||||||
|
|
|
@ -21,8 +21,7 @@ M: assoc-heap heap-push* ( value key assoc-heap -- entry )
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
M: assoc-heap heap-pop ( assoc-heap -- value key )
|
M: assoc-heap heap-pop ( assoc-heap -- value key )
|
||||||
[ heap>> heap-pop ] keep
|
heap>> heap-pop ;
|
||||||
[ over ] dip assoc>> delete-at ;
|
|
||||||
|
|
||||||
M: assoc-heap heap-peek ( assoc-heap -- value key )
|
M: assoc-heap heap-peek ( assoc-heap -- value key )
|
||||||
heap>> heap-peek ;
|
heap>> heap-peek ;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2008 Doug Coleman.
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: help.markup help.syntax io.streams.string urls
|
USING: help.markup help.syntax io.streams.string urls
|
||||||
multiline ;
|
multiline spider.private quotations ;
|
||||||
IN: spider
|
IN: spider
|
||||||
|
|
||||||
HELP: <spider>
|
HELP: <spider>
|
||||||
|
@ -16,12 +16,6 @@ HELP: run-spider
|
||||||
{ "spider" spider } }
|
{ "spider" spider } }
|
||||||
{ $description "Runs a spider until completion. See the " { $subsection "spider-tutorial" } " for a complete description of the tuple slots that affect how thet spider works." } ;
|
{ $description "Runs a spider until completion. See the " { $subsection "spider-tutorial" } " for a complete description of the tuple slots that affect how thet spider works." } ;
|
||||||
|
|
||||||
HELP: spider
|
|
||||||
{ $description "" } ;
|
|
||||||
|
|
||||||
HELP: spider-result
|
|
||||||
{ $description "" } ;
|
|
||||||
|
|
||||||
HELP: slurp-heap-when
|
HELP: slurp-heap-when
|
||||||
{ $values
|
{ $values
|
||||||
{ "heap" "a heap" } { "quot1" quotation } { "quot2" quotation } }
|
{ "heap" "a heap" } { "quot1" quotation } { "quot2" quotation } }
|
||||||
|
|
|
@ -8,7 +8,7 @@ combinators.short-circuit continuations calendar prettyprint ;
|
||||||
IN: spider
|
IN: spider
|
||||||
|
|
||||||
TUPLE: spider base count max-count sleep max-depth initial-links
|
TUPLE: spider base count max-count sleep max-depth initial-links
|
||||||
filters spidered todo nonmatching ;
|
filters spidered todo nonmatching quiet ;
|
||||||
! secure? agent page-timeout data-timeout overall-timeout
|
! secure? agent page-timeout data-timeout overall-timeout
|
||||||
|
|
||||||
TUPLE: spider-result url depth headers fetch-time parsed-html
|
TUPLE: spider-result url depth headers fetch-time parsed-html
|
||||||
|
@ -27,19 +27,19 @@ links processing-time timestamp ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
: relative-url? ( url -- ? ) protocol>> not ;
|
||||||
|
|
||||||
: apply-filters ( links spider -- links' )
|
: apply-filters ( links spider -- links' )
|
||||||
filters>> [ '[ _ 1&& ] filter ] when* ;
|
filters>> [ '[ _ 1&& ] filter ] when* ;
|
||||||
|
|
||||||
|
: push-links ( links level assoc-heap -- )
|
||||||
|
'[ _ _ heap-push ] each ;
|
||||||
|
|
||||||
: add-todo ( links level spider -- )
|
: add-todo ( links level spider -- )
|
||||||
tuck [ apply-filters ] 2dip
|
todo>> push-links ;
|
||||||
tuck
|
|
||||||
[ spidered>> keys diff ]
|
|
||||||
[ todo>> ] 2bi* '[ _ _ heap-push ] each ;
|
|
||||||
|
|
||||||
: add-nonmatching ( links level spider -- )
|
: add-nonmatching ( links level spider -- )
|
||||||
nonmatching>> '[ _ _ heap-push ] each ;
|
nonmatching>> push-links ;
|
||||||
|
|
||||||
: relative-url? ( url -- ? ) protocol>> not ;
|
|
||||||
|
|
||||||
: filter-base ( spider spider-result -- base-links nonmatching-links )
|
: filter-base ( spider spider-result -- base-links nonmatching-links )
|
||||||
[ base>> host>> ] [ links>> prune ] bi*
|
[ base>> host>> ] [ links>> prune ] bi*
|
||||||
|
@ -51,26 +51,27 @@ links processing-time timestamp ;
|
||||||
[ filter-base ] 2keep
|
[ filter-base ] 2keep
|
||||||
depth>> 1+ swap
|
depth>> 1+ swap
|
||||||
[ add-nonmatching ]
|
[ add-nonmatching ]
|
||||||
[ add-todo ] 2bi ;
|
[ tuck [ apply-filters ] 2dip add-todo ] 2bi ;
|
||||||
|
|
||||||
: print-spidering ( url depth -- )
|
|
||||||
"depth: " write number>string write
|
|
||||||
", spidering: " write . yield ;
|
|
||||||
|
|
||||||
: normalize-hrefs ( links -- links' )
|
: normalize-hrefs ( links -- links' )
|
||||||
[ >url ] map
|
[ >url ] map
|
||||||
spider get base>> swap [ derive-url ] with map ;
|
spider get base>> swap [ derive-url ] with map ;
|
||||||
|
|
||||||
|
: print-spidering ( url depth -- )
|
||||||
|
"depth: " write number>string write
|
||||||
|
", spidering: " write . yield ;
|
||||||
|
|
||||||
: (spider-page) ( url depth -- spider-result )
|
: (spider-page) ( url depth -- spider-result )
|
||||||
2dup print-spidering
|
|
||||||
f pick spider get spidered>> set-at
|
f pick spider get spidered>> set-at
|
||||||
over '[ _ http-get ] benchmark swap
|
over '[ _ http-get ] benchmark swap
|
||||||
[ parse-html dup find-hrefs normalize-hrefs ] benchmark
|
[ parse-html dup find-hrefs normalize-hrefs ] benchmark
|
||||||
now spider-result boa
|
now spider-result boa ;
|
||||||
dup describe ;
|
|
||||||
|
|
||||||
: spider-page ( url depth -- )
|
: spider-page ( url depth -- )
|
||||||
(spider-page) spider get swap add-spidered ;
|
spider get quiet>> [ 2dup print-spidering ] unless
|
||||||
|
(spider-page)
|
||||||
|
spider get [ quiet>> [ dup describe ] unless ]
|
||||||
|
[ swap add-spidered ] bi ;
|
||||||
|
|
||||||
\ spider-page ERROR add-error-logging
|
\ spider-page ERROR add-error-logging
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue