2008-06-10 19:32:44 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								USING:  help.markup  help.syntax  kernel  quotations  
						 
					
						
							
								
									
										
										
										
											2008-11-16 06:53:25 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								deques search-deques hashtables ;
 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-05 02:41:23 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								IN:  dlists  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-06-10 19:32:44 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								ARTICLE: "dlists"  "Double-linked lists" 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-19 15:06:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"A double-linked list is the canonical implementation of a "  { $link deque } "."  
						 
					
						
							
								
									
										
										
										
											2007-11-05 11:01:11 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								$nl
							 
						 
					
						
							
								
									
										
										
										
											2008-06-10 19:32:44 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								"Double-linked lists form a class:"  
						 
					
						
							
								
									
										
										
										
											2007-11-05 11:01:11 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{ $subsection dlist }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $subsection dlist? }
							 
						 
					
						
							
								
									
										
										
										
											2008-06-10 19:32:44 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								"Constructing a double-linked list:"  
						 
					
						
							
								
									
										
										
										
											2007-11-05 11:01:11 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{ $subsection <dlist> }
							 
						 
					
						
							
								
									
										
										
										
											2008-08-19 15:06:20 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"Double-linked lists support all the operations of the deque protocol ("  { $link "deques"  } ") as well as the following."  
						 
					
						
							
								
									
										
										
										
											2008-06-10 19:32:44 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								$nl
							 
						 
					
						
							
								
									
										
										
										
											2007-11-05 11:01:11 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								"Iterating over elements:"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $subsection dlist-each }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $subsection dlist-find }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $subsection dlist-contains? }
							 
						 
					
						
							
								
									
										
										
										
											2008-01-31 01:52:06 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								"Deleting a node matching a predicate:"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $subsection delete-node-if* }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-16 06:53:25 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $subsection delete-node-if }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"Search deque implementation:"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $subsection <hashed-dlist> } ;
 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-05 11:01:11 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ABOUT: "dlists" 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-05 02:41:23 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-11-16 06:59:14 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								HELP:  <dlist>  
						 
					
						
							
								
									
										
										
										
											2008-11-16 08:04:51 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $values { "list"  dlist } }
							 
						 
					
						
							
								
									
										
										
										
											2008-11-16 06:59:14 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $description "Creates a new double-linked list."  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  <hashed-dlist>  
						 
					
						
							
								
									
										
										
										
											2008-11-16 06:53:25 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								{ $values { "search-deque"  search-deque } }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $description "Creates a new "  { $link search-deque } " backed by a "  { $link dlist } ", with a "  { $link hashtable } " for fast membership tests."  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-11-05 02:41:23 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								HELP:  dlist-find  
						 
					
						
							
								
									
										
										
										
											2008-03-20 21:14:07 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{ $values { "dlist"  { $link dlist } } { "quot"  quotation } { "obj/f"  "an object or "  { $link f  } } { "?"  "a boolean"  } }
							 
						 
					
						
							
								
									
										
										
										
											2007-11-05 02:41:23 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{ $description "Applies the quotation to each element of the "  { $link dlist } " in turn, until it outputs a true value or the end of the "  { $link dlist } " is reached.  Outputs either the object it found or "  { $link f  } ", and a boolean which is true if an object is found."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $notes "Returns a boolean to allow dlists to store "  { $link f  } "." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    $nl
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "This operation is O(n)." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  dlist-contains?  
						 
					
						
							
								
									
										
										
										
											2008-03-20 21:14:07 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{ $values { "dlist"  { $link dlist } } { "quot"  quotation } { "?"  "a boolean"  } }
							 
						 
					
						
							
								
									
										
										
										
											2007-11-05 02:41:23 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{ $description "Just like "  { $link dlist-find } " except it doesn't return the object."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $notes "This operation is O(n)."  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-01-31 01:52:06 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								HELP:  delete-node-if*  
						 
					
						
							
								
									
										
										
										
											2008-03-20 21:14:07 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{ $values { "dlist"  { $link dlist } } { "quot"  quotation } { "obj/f"  "an object or "  { $link f  } } { "?"  "a boolean"  } }
							 
						 
					
						
							
								
									
										
										
										
											2007-11-05 02:41:23 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{ $description "Calls "  { $link dlist-find } " on the "  { $link dlist } " and deletes the node returned, if any.  Returns the value of the deleted node and a boolean to allow the deleted value to distinguished from "  { $link f  } ", for nothing deleted."  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{ $notes "This operation is O(n)."  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-01-31 01:52:06 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								HELP:  delete-node-if  
						 
					
						
							
								
									
										
										
										
											2008-03-20 21:14:07 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{ $values { "dlist"  { $link dlist } } { "quot"  quotation } { "obj/f"  "an object or "  { $link f  } } }
							 
						 
					
						
							
								
									
										
										
										
											2008-01-31 01:52:06 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{ $description "Like "  { $link delete-node-if* } " but cannot distinguish from deleting a node whose value is "  { $link f  } " or not deleting an element."  }
							 
						 
					
						
							
								
									
										
										
										
											2007-11-05 02:41:23 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{ $notes "This operation is O(n)."  } ;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								HELP:  dlist-each  
						 
					
						
							
								
									
										
										
										
											2008-03-20 21:14:07 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{ $values { "dlist"  { $link dlist } } { "quot"  quotation } }
							 
						 
					
						
							
								
									
										
										
										
											2007-11-05 02:41:23 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								{ $description "Iterate a "  { $link dlist } ", calling quot on each element."  } ;