public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: Craig Ringer <craig@2ndquadrant.com>
To: systemtap@sourceware.org
Subject: Associative array "pop" ?
Date: Thu, 21 Jan 2021 10:32:11 +0800	[thread overview]
Message-ID: <CAMsr+YHEj7wKsvRXy0bKxfzAnCYeQ09C5NJUsOYPw+Yyb5P-9Q@mail.gmail.com> (raw)

Hi all

I find myself using the patterns

x_foo = foo[x]
if (x_foo != 0)
    delete foo[x]
    # do something with x_foo
}

and

if ([x] in foo) {
    x_foo = foo[x]
    delete foo[x]
    # do something with x_foo
}

frequently.

I wonder if it's feasible to have a "pop" that combines these to eliminate
repeated searches of the array. Assuming that those aren't already
optimised away - I didn't see any indication they are, but don't know the
underlying code well enough.

Something like

    if (pop(foo_x, foo[x])) {
    }

where "pop" returns 1 if the element was present, 0 if it was not present,
and deletes it if it was present.

If you think it's a good idea I'll pop this on my TODO for pending
enhancements for me to try to hack up.

-- 
 Craig Ringer                   http://www.2ndQuadrant.com/
 2ndQuadrant - PostgreSQL Solutions for the Enterprise

             reply	other threads:[~2021-01-21  2:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-21  2:32 Craig Ringer [this message]
2021-02-16 21:40 ` Frank Ch. Eigler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMsr+YHEj7wKsvRXy0bKxfzAnCYeQ09C5NJUsOYPw+Yyb5P-9Q@mail.gmail.com \
    --to=craig@2ndquadrant.com \
    --cc=systemtap@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).