--		Copyright 1994,2010 by Daniel R. Grayson
use common;
bucketsfun(e:Expr):Expr := (
     when e
     is dc:DictionaryClosure do (
	  d := dc.dictionary;
	  Expr(
	       list(
		    new Sequence len length(d.symboltable.buckets) do (
			 foreach b in d.symboltable.buckets do (
			      n := 0;
			      c := b;
			      while ( when c is null do false is cell:SymbolListCell do (c = cell.next; true) ) do n = n+1;
			      c = b;
			      provide list(
				   new Sequence len n do
				   while (
					when c
					is null do false
					is cell:SymbolListCell do (
					     sym := cell.entry;
					     provide Expr(
						  Sequence(
						       Expr(stringCell(cell.word.name)),
						       SymbolClosure(if sym.thread then threadFrame else dc.frame,sym)));
					     c = cell.next;
					     true)
					)
				   do nothing))))))
     is h:HashTable do list(
	  new Sequence len length(h.table) do (
	       foreach pp in h.table do (
		    n := 0;
		    p := pp;
		    while true do (
			 if p == p.next then break;
			 n = n+1;
			 p = p.next);
		    p = pp;
		    s := new Sequence len n do (
			 provide Expr(Sequence(p.key, p.value));
			 p = p.next);
		    provide list(s))))
     else WrongArg("a hash table"));
setupfun("buckets",bucketsfun);

-- Local Variables:
-- compile-command: "echo \"make: Entering directory \\`$M2BUILDDIR/Macaulay2/d'\" && make -C $M2BUILDDIR/Macaulay2/d buckets.o "
-- End:
