f



Re: getting some key in a hash table

Peter Seibel wrote:

> Jim Newton <jimka@rdrop.com> writes:
> 
> > Is there any way to get some key of a hash table?
> > I do not care which one I get, any one will do.
> >
> > The function maphash will map a function over ALL the key/value
> > pairs of the hash table, but i only one to get one element. I could
> > build some sort of catch/throw around a maphash but that seems a bit
> > excessive.
> 
> And from the why-not-use-loop-for-everything dept.:
> 
>   (loop for key being the hash-keys in hash return key)
> 
> Or if you want a random key:
> 
>   (loop with nth = (random (hash-table-count hash))
>         for key being the hash-keys in hash
>         for i from 0
>         when (= i nth) return key)

Racket:

  > (hash 'a 1 'b 2 'c 3 'd 4)
  '#hash((c . 3) (b . 2) (a . 1) (d . 4))
  > (hash-keys (hash 'a 1 'b 2 'c 3 'd 4))
  '(c b a d)


EMACS Lisp:

(require 'cl)
(block nil
  (maphash (lambda (k v) (return k)) 
    #s(hash-table data (a 1 b 2 c 3 d 4))))
0
w_a_x_man (3241)
12/14/2012 2:38:32 PM
comp.lang.lisp 16861 articles. 5 followers. Post Follow

2 Replies
601 Views

Similar Articles

[PageSpeed] 59

Peter Seibel wrote:

> Jim Newton <jimka@rdrop.com> writes:
> 
> > Is there any way to get some key of a hash table?
> > I do not care which one I get, any one will do.
> >
> > The function maphash will map a function over ALL the key/value
> > pairs of the hash table, but i only one to get one element. I could
> > build some sort of catch/throw around a maphash but that seems a bit
> > excessive.
> 
> And from the why-not-use-loop-for-everything dept.:
> 
>   (loop for key being the hash-keys in hash return key)
> 
> Or if you want a random key:
> 
>   (loop with nth = (random (hash-table-count hash))
>         for key being the hash-keys in hash
>         for i from 0
>         when (= i nth) return key)

MatzLisp (Ruby):

h = Hash[:eeny,2,:meeny,3,:miney,4,:mo,5]

h.values.sample
    ==>5
h.values.sample
    ==>4
h.values.sample
    ==>3
h.values.sample
    ==>4

-- 
When I was a Revolutionary Marxist, we were all in favour of as much
immigration as possible.  It wasn't because we liked immigrants, but because we
didn't like Britain.
dailymail.co.uk/news/article-2301743/How-invasion-immigrants-corner-England-mockery-PMs-promise-close-door.html
0
WJ
8/3/2016 10:53:57 PM
WJ wrote:

> Peter Seibel wrote:
> 
> > Jim Newton <jimka@rdrop.com> writes:
> > 
> > > Is there any way to get some key of a hash table?
> > > I do not care which one I get, any one will do.
> > > 
> > > The function maphash will map a function over ALL the key/value
> > > pairs of the hash table, but i only one to get one element. I could
> > > build some sort of catch/throw around a maphash but that seems a bit
> > > excessive.
> > 
> > And from the why-not-use-loop-for-everything dept.:
> > 
> >   (loop for key being the hash-keys in hash return key)
> > 
> > Or if you want a random key:
> > 
> >   (loop with nth = (random (hash-table-count hash))
> >         for key being the hash-keys in hash
> >         for i from 0
> >         when (= i nth) return key)
> 
> MatzLisp (Ruby):
> 
> h = Hash[:eeny,2,:meeny,3,:miney,4,:mo,5]
> 
> h.values.sample
>     ==>5
> h.values.sample
>     ==>4
> h.values.sample
>     ==>3
> h.values.sample
>     ==>4

If a key is actually wanted:

h.keys.sample
    ==>:miney
h.keys.sample
    ==>:eeny
h.keys.sample
    ==>:eeny
h.keys.sample
    ==>:miney
h.keys.sample
    ==>:meeny

-- 
After being told there was no money, the attackers tore off the woman's clothes
and raped her until five others arrived, according to the documents.  The new
arrivals took turns having sex with her and then sodomized her....  At gunpoint,
the assailants forced the mother and son to have sex.
www.sun-sentinel.com/local/palm-beach/sfl-flpdunbar0822nbaug22-story.html
0
WJ
8/3/2016 11:01:34 PM
Reply:

Similar Artilces:

getting some key in a hash table
Is there any way to get some key of a hash table? I do not care which one I get, any one will do. The function maphash will map a function over ALL the key/value pairs of the hash table, but i only one to get one element. I could build some sort of catch/throw around a maphash but that seems a bit excessive. -jim On Sat, 17 Jul 2004 21:58:36 +0200, Jim Newton <jimka@rdrop.com> wrote: >Is there any way to get some key of a hash table? >I do not care which one I get, any one will do. > >The function maphash will map a function over ALL >the key/value pairs of the hash ...

Re: keys of hash table
Peter Van Eynde wrote: > On 25 Jun 1999 13:31:18 +0100 (BST), Mark Carroll wrote: > > >I can't find an easy way of obtaining a list of the keys of a hash > >table in Common Lisp. Can anyone do better than, > > >(defun keys-of-hash-table (ht) > > (let ((keys nil)) > > (labels ((getkey (x y) (push x keys))) > > (maphash #'getkey ht) > > keys))) > > (defun keys-of-hash-table (ht) > (loop for key being the hash-keys in ht > collect key)) Racket: > (hash-keys (hash 'a 1 'b 2 ...

Re: Getting a random hash-table element?
Ken Tilton wrote: > When you are ready (and don't wait too long) learn loop: > > (defun gre-fss (h) > (loop for x downfrom (random (hash-table-count h)) > for v being the hash-values of h > when (zerop x) return v)) Racket: (define (gre-fss h) (list-ref (hash-values h) (random (hash-count h)))) WJ wrote: > Ken Tilton wrote: > > > When you are ready (and don't wait too long) learn loop: > > > > (defun gre-fss (h) > > (loop for x downfrom (random (hash-table-count h)) > > for v being the hash-values of h > > when (zerop x) return v)) > > > Racket: > > (define (gre-fss h) > (list-ref (hash-values h) (random (hash-count h)))) Clojure: (defn gre-fss [h] (nth (vals h) (rand-int (count h)))) ...

Re: [Uniface-L] Getting a unique value (not a prim key) from a table
This is a multi-part message in MIME format. --=-------------11195896669140832192 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Hi, just put the desired value in the field and issue a "retrieve". This will = select all records, which match the profile, in the case of a unique value= exactly onr record. myregisternumber =3D "12356"=20 retrieve Success, Uli Uniface User Group Discussion Forum <uniface-l@uug.org> schrieb am 24.06.0= 5 01:34:53: >=20 > Hi All, >=20 > If i want to retriev...

Re: Using a Hash table to remove a reversed key value observation
I would also, go with your Hash solution. Here's a DOW loop solution: Data want; do until(last.fid); set rev; by fid; length _oname $3; _flag=( nam=reverse(_oname) ); _oname=nam; if _flag=0 then output; end; drop _:; Run; On Sun, Apr 19, 2009 at 7:48 PM, <xlr82sas@aol.com> wrote: > Hi, > > Am I working too hard(the real example is much more complex with > thousands of records) > > Primary key is fid nam. > > INPUT > > data rev; > input fid nam $; > cards; > 1 hym > 1 myh > 1 rog...

Re: Using a Hash table to remove a reversed key value observation #4
> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On > Behalf Of Akshaya > Sent: Sunday, April 19, 2009 6:53 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: Using a Hash table to remove a reversed key > value observation > > I would also, go with your Hash solution. Here's a DOW loop solution: > Data want; > do until(last.fid); > set rev; > by fid; > length _oname $3; > _flag=( nam=reverse(_oname) ); > _oname=nam; > if _flag=0 then output; > end;...

Re: Using a Hash table to remove a reversed key value observation #6
You can do it quite simply in SQL: proc sql; create table want as select * from rev a where nam not in( select left(reverse(nam)) from rev b where a.fid=b.fid and a.nam>b.nam); I do not know how the performance compares to the hash solution. Does it matter? Most often, it is better to use a simpler solution which is easier to understand and maintain. Regards, Søren On Sun, 19 Apr 2009 16:48:19 -0700, xlr82sas@AOL.COM wrote: >Hi, > >Am I working too hard(the real example is much more complex with >thousands of records) > >Primary key ...

Re: Using a Hash table to remove a reversed key value observation #5
On Sun, Apr 19, 2009 at 7:48 PM, <xlr82sas@aol.com> wrote: > Hi, > > Am I working too hard(the real example is much more complex with > thousands of records) > > Primary key is fid nam. > > INPUT > > data rev; > input fid nam $; > cards; > 1 hym > 1 myh > 1 rog > 2 lak > ; > run; > > OUTPUT > > 1 hym > 1 rog > 2 lak > > > All I want to do is remove records where the second key is reversed > within the same fid group. > There can be at most one reversal in each fid group. It does not > matter which ...

Re: Using a Hash table to remove a reversed key value observation #2
I think the hash solution is probably the best one, in terms of efficiency. I could posit a two-set-statement solution or a SQL solution, but both would probably be longer code and both would certainly be less efficient for 99% of possible data sets if not 100%. I won't say whether your particular hash solution is perfect, as I'm only a novice at hash, but I'd think that sort of thing is what it's best for really. The SQL solution I would imagine would involve joining the table A with the table with reversed codes B, and taking where A not in B, unioned with half of the table...

Re: Using a Hash table to remove a reversed key value observation #3
On Sun, 19 Apr 2009 16:48:19 -0700, xlr82sas@AOL.COM wrote: .... >All I want to do is remove records where the second key is reversed >within the same fid group. >There can be at most one reversal in each fid group. It does not >matter which one I keep, but I want only one. .... hi, this maybe less efficient than yours. hth. cheers, chang /* test data */ data one; input fid nam $3.; cards; 1 hym 1 myh 1 rog 2 lak ; run; /* remove any duplicated or reversed key within id group */ proc sort data=one; by fid; run; data two; if 0 then set one; /* to prep pdv */ dcl hash h()...

Re : Re: How to get row number in table.
That's exacly my problem. My problem is that I don't know the number of row it could be more or less. The Vi where I need to know the number of row, receive the table from an other VI &nbsp; ...

Re: TABLES TABLES TABLES
sasbum@AOL.COM wrote: >How would you best describe to a retiscent SAS student that the concept of >TABLES isn't limited to SQL? This came up during a discussion on table >lookup methods - and lookup tables in particular (I mean, lookup tables >pre- >date SQL). Even SAS data sets are referred to as tables. This made the >student apoplectic. I find a visual works well here. If you show a grid with rows and columns, then you can show a picture of a SAS data set and a SQL table and a lookup table, and show that (regardless of terminology and buzzwords) they're all pr...

Get all child table and key names of a parent table
select stab.tabname Parent, scol.colname Primary_key, sstab.tabname Child, sscol.colname Child_key from syscolumns scol, syscolumns sscol, sysindexes sind, sysindexes ssind, sysconstraints scon, sysconstraints sscon, systables stab, systables sstab, sysreferences sref where scol.tabid=sind.tabid and scol.colno = sind.part1 and sind.idxname=scon.idxname and stab.tabid=scon.tabid and sstab.tabid=sscon.tabid and sscol.tabid = ssind.tabid and (sscol.colno = ssind.part1 or sscol.colno = ssind.part2) and sscon.idxname=ssind.idxname and sref.constrid=sscon.constrid and stab.tabid=sref.ptabid and stab.tabname='ParentTableName' above query works gr8 when single column primary key in Parent table, but when there is two or morecolumn primary key it does not gives right ans. plz try to solve.. "Kuldeep" <kuldeepchitrakar@gmail.com> wrote in message news:1144752804.917120.279890@i39g2000cwa.googlegroups.com... > select stab.tabname Parent, > scol.colname Primary_key, > sstab.tabname Child, > sscol.colname Child_key > from syscolumns scol, > syscolumns sscol, > sysindexes sind, > sysindexes ssind, > sysconstraints scon, > sysconstraints sscon, > systables stab, > systables sstab, > sysreferen...

re: Get table data into separate div from table header
For a course management portal we use, it would be nice to have when an instructor scrolls through grades that the column names stays on the screen. One thought I had was to have the body or headers be in a separate div, but, regardless, I am curious how I would dynamically modify a table so that the two scroll separately. I realize I need to put javascript in the head tag, at the onload event, and find the table dynamically. The DOM parts I can do, for me the issue is, is it possible to just separate them like this? Thanx. ...

Re: Newbie Questio.. Getting a Virtual address space full and global page table full error.. How to repair.? page table full error.. How to repair.? page table full error.. How to repair.?
On 5/21/05, David J Dachtera <djesys.nospam@comcast.net> wrote: > Bruce Cooke wrote: > > > > Hi > > I have a Vaxstation 4000 60, vms 5.5 , 2 rz23l hard drives , and when > > booting get the subject messages. The computer wont boot into dec windo= ws, > > so the only way in is thru the DCL sysboot menu.I know there are spare > > blocks on the boot drive but have no idea how to fix no virtual address > > space error Any one > > here know how to solve this? >=20 > Well, Peter suggested AUTOGEN. If you don't know what that is, I...

Keys of hash-table
> >I can't find an easy way of obtaining a list of the keys of a hash > >table in Common Lisp. Can anyone do better than, > > >(defun keys-of-hash-table (ht) > > (let ((keys nil)) > > (labels ((getkey (x y) (push x keys))) > > (maphash #'getkey ht) > > keys))) > > (defun keys-of-hash-table (ht) > (loop for key being the hash-keys in ht > collect key)) Factor: USE: locals :: try ( -- ) H{ } clone :> table "aa" table inc-at "bb" table inc-at "cc" table inc-at 899 "dd" table set-at table . table keys . ; try H{ { "aa" 1 } { "bb" 1 } { "dd" 899 } { "cc" 1 } } { "aa" "bb" "dd" "cc" } ...

Re: Hash Tables
This is a multi-part message in MIME format. ------=_NextPart_000_004C_01C3E5F3.B6FDB600 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable A hash join (or any join for that matter) is between two tables - if you = look at the explain plan for a query it will show (well, if you can = decipher it properly) pairs of tables being joined. So if you are = joining three tables, the optimizer will look at your query, figure out = which two of the three (or 18) should be joined first, which of those = two is 'smaller' and use that to build the hash table, it will then = probe with the second table. The results of that join will be used to = build the next hash table - which will then be probed by the next table = in the chain and so on...... cheers j. ----- Original Message -----=20 From: Wilkinson, Marcus=20 To: 'informix-list@iiug.org'=20 Sent: Wednesday, January 28, 2004 7:36 PM Subject: Hash Tables Hi, Could anyone explain to me exactly what happens when you perform a = hash join between multiple tables. The Informix doc I have read only = references a two table join. It says that a hash table is built of the = driving table and matched against hash values of the second table. = What happens if there is a third and fourth table? Would more than one hash table be built? How can I determine how big the hash table(s) will be and how ...

Re: TABLES TABLES TABLES #4
Howard: Although Date and Celko follow the usual convention when they call the sole data structure in SQL a 'table', Codd tended to prefer 'relation'. The concept has a long history in mathematics and logic. Before SQL, before SAS, before IBM, and even before Babbage .... A relational database has one or more tables. Neither 'database' nor 'table' implies anything about the implementation of a database or table in a database or file management system. If a data structure has the properties of a table (column variables in rows), it's a table. Nothing more, n...

RE: How to get database metadata information (i.e. existing tables andcolumns in tables)
[Chris=20Brat] |=20Is=20it=20possible=20to=20retrieve=20details=20about=20the=20database,= =20specifically=20a |=20list=20of=20the=20tables=20in=20the=20database;=20and=20then=20to=20re= trieve=20the=20columns |=20and=20their=20types=20for=20the=20tables? |=20 |=20Is=20this=20dependant=20on=20the=20database?=20 In=20effect=20it's=20dependent=20on=20the=20database.=20We're=20assuming=20= you're talking=20about=20a=20relational=20databases=20for=20a=20start,=20since=20= other databases=20don't=20necessarily=20even=20have=20tables.=20The=20major=20da= tabases may=20support=20the...

Re: Hashing with SAS9.2 using multiple hash keys and a date range
Hi Rob, I think you are looking for the multidata: 'y' option This seems to produce the desired results, although I had to impute the todate to todays date when missing, to match your example output (using: todate = coalesce(todate,today()) ;) : data want ; if 0 then set clientDiscount ; declare hash hh(dataset:'clientDiscount', multidata:'y') ; hh.definekey('clientid'); hh.definedata('fromdate','todate','clientDiscount') ; hh.definedone() ; do until(eof) ; set salesHistory end=eof ; _rc = hh.find() ; ...

Re: TABLES TABLES TABLES #5
LOL -- I told him I had a table in my dining room, and another kind in my kitchen, etc. -----Original Message----- From: Ed Heaton <EdHeaton@westat.com> To: Howard Wood <sasbum@AOL.COM> Sent: Mon, 28 Nov 2005 08:44:38 -0500 Subject: RE: TABLES TABLES TABLES Howard, Maybe you should turn the tables on him and correct him whenever he refers to a sedan as a car or to beef as meat or to an engine as a motor. Ed Ed Heaton RW-4541 #4818 -----Original Message----- From: owner-sas-l@listserv.uga.edu [mailto:owner-sas-l@listserv.uga.edu] On Behalf Of Howard Wood Sent: Saturday, Nov...

Re: TABLES TABLES TABLES #2
OHHH went there, did that, got the t-shirt, even. I tried everything in the book. This person is extremely LITERAL and looking for the letter of the law, or something........maybe my trying so hard just egged him on, or his stubbornness that kept his feet in concrete, but I don't think so. He truly believes that. -----Original Message----- From: David L Cassell <davidlcassell@MSN.COM> To: SAS-L@LISTSERV.UGA.EDU Sent: Sun, 27 Nov 2005 11:55:12 -0800 Subject: Re: TABLES TABLES TABLES sasbum@AOL.COM wrote: >How would you best describe to a retiscent SAS student that the concept...

Re: hash table
Have a look at my %HASHMERGE macro. http://www2.sas.com/proceedings/forum2008/107-2008.pdf Regards, Gregg Snell -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Scott Raynaud Sent: Friday, June 20, 2008 11:14 AM To: SAS-L@LISTSERV.UGA.EDU Subject: hash table i'm using the hash below to accomplish a merge. there is no merge statement, hence no alias names to indicate what's in what. i'd like to modify the code below to do the following (separately, of course): say i have two tables, A and B. 1) keep everything in A but drop any...

Re: TABLES TABLES TABLES #6
Ahhhh - I'm lovin' that one. TY TY In a message dated 12/1/2005 6:14:05 AM Eastern Standard Time, rdevenezia@WILDBLUE.NET writes: Friar Broccoli wrote: > Try this (a higher authority): > > http://www.google.com/search?num=100&hl=en&lr=lang_en&safe=off&as_qdr=all&q=de fine%3A+data+table&btnG=Search&lr=lang_en > > Howard Wood wrote: >> OHHH went there, did that, got the t-shirt, even. I tried >> everything in the book. This person is extremely LITERAL and >> looking for the letter of the law, or something........maybe...

Web resources about - Re: getting some key in a hash table - comp.lang.lisp

Cliven Bundy Faces Life In Prison, Supporters Demonstrate At Courthouse
Cliven Bundy, accused of leading an armed standoff two years ago, drew crowds of supporters at his arraignment. The Bundy family organized the ...

Waze 4.0 Launches on Google Play, Fancy ETA Panel and Improved Power Consumption
After much teasing, Waze 4.0 is officially available on Google Play, bringing a gang of changes to Android users. Inside, Waze has “significantly” ...

You'll Finally Be Able To Stop This Annoying Facebook Notification
If you're fed up with endless Facebook Live notifications, fret no more: A fix is coming. Facebook will soon let users disable all notifications ...

Shooting Near Pittsburgh Kills 5 and Wounds 3 at Party
New York Times Shooting Near Pittsburgh Kills 5 and Wounds 3 at Party New York Times The police in a Pittsburgh suburb on Thursday were searching ...

Apple confirms special event to 'loop in' the press March 21
The rumors were right (well, eventually ): Apple is having a special event for members of the press at 10:00 a.m. on Monday, March 21, at the ...

Kelly Clarkson Clarifies Dr. Luke Blackmail Claims, As His War With Ke$ha Continues
Kelly Clarkson recently joined the chorus of voices against Dr. Luke, who is currently involved in a highly publicized legal fight with Ke$ha. ...

Apple warns that FBI could monitor cameras and microphones next
If you've been following the case between Apple and the FBI, then you know that Apple has been asked to create a new, insecure version of iOS ...

Islamic State defector brings 'goldmine' of details on 22,000 supporters
By Guy Faulconbridge LONDON (Reuters) - A disillusioned former member of Islamic State has passed a stolen memory stick of documents identifying ...

Kim Kardashian’s Nude Selfies Followed By ‘Skin Tight’ Bodysuit And Hot Post Baby Body
After a huge internet blow up over Kim Kardashian’s selfies featuring her nude body tastefully disguised with black bars over her “private parts,” ...

Berkeley School of Law Dean Downgraded to Professor After Admitting He Sexually Harassed Employees
Shortly after executive assistant Tyann Sorrell filed a sexual harassment lawsuit against UC Berkeley School of Law dean Sujit Choudhry, the ...

Resources last updated: 3/10/2016 10:53:52 AM