Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

Re: Hashtable iteration: performing early breaks

已查看 22 次
跳至第一个未读帖子

WJ

未读,
2015年10月16日 17:59:352015/10/16
收件人
为什么将此帖子标记为存在滥用行为? 此帖子已被标记为存在滥用行为。
报告不存在滥用行为
Frode Vatvedt Fjeld wrote:

> (defun confirm-loaded (n-val)
> "Scan the current contents of *data* and confirm whether or not n-val
> already exists."
> (let ((match-key nil))
> (prog
> (maphash #'(lambda (k v)
> (when (equalp n-val v)
> (setf match-key k)
> (go done)))
> *data*)
> done)
> match-key))

Gauche Scheme:

(use gauche.generator :only (x->generator))

(define (hash-table-val-exists? ht val)
(generator-find
(lambda (k.v) (equal? val (cdr k.v)))
(x->generator ht)))

--
What I would most desire would be the separation of the white and black
races. --- A. Lincoln, July 17, 1858

WJ

未读,
2015年10月31日 07:36:172015/10/31
收件人
WJ wrote:

> Frode Vatvedt Fjeld wrote:
>
> > (defun confirm-loaded (n-val)
> > "Scan the current contents of data and confirm whether or not n-val
> > already exists."
> > (let ((match-key nil))
> > (prog
> > (maphash #'(lambda (k v)
> > (when (equalp n-val v)
> > (setf match-key k)
> > (go done)))
> > data)
> > done)
> > match-key))
>
> Gauche Scheme:
>
> (use gauche.generator :only (x->generator))
>
> (define (hash-table-val-exists? ht val)
> (generator-find
> (lambda (k.v) (equal? val (cdr k.v)))
> (x->generator ht)))

The problem is to find the key corresponding to a value
without scanning the entire hash-table.

MatzLisp (Ruby):

h = { "a" => 100, "b" => 200, "c" => 300, "d" => 300 }
h.key(200) #=> "b"
h.key(300) #=> "c"
h.key(999) #=> nil

--
A separation of the races is the only perfect preventive of amalgamation; but
as an immediate separation is impossible, the next best thing is to keep them
apart where they are not already together. If white and black people never get
together in Kansas, they will never mix blood in Kansas.
--- A. Lincoln, June 26, 1857

WJ

未读,
2016年6月28日 03:52:092016/6/28
收件人
WJ wrote:

> Frode Vatvedt Fjeld wrote:
>
> > (defun confirm-loaded (n-val)
> > "Scan the current contents of *data* and confirm whether or not n-val
> > already exists."
> > (let ((match-key nil))
> > (prog
> > (maphash #'(lambda (k v)
> > (when (equalp n-val v)
> > (setf match-key k)
> > (go done)))
> > *data*)
> > done)
> > match-key))
>
> Gauche Scheme:
>
> (use gauche.generator :only (x->generator))
>
> (define (hash-table-val-exists? ht val)
> (generator-find
> (lambda (k.v) (equal? val (cdr k.v)))
> (x->generator ht)))

OCaml:

let val_exists ht value =
try (Hashtbl.iter
(fun k v -> if v = value then raise Exit)
ht ;
false)
with Exit -> true ;;

--
Europe is not going to be the monolithic societies that they once were in the
last century.... They are now going into a multicultural mode. Jews will be
resented because of our leading role. --- Barbara Spectre
archive.org/download/DavidDuke_videos/HowZionistsDivideAndConquer-fjjszxkm55o.ogv
0 个新帖子