From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by sourceware.org (Postfix) with ESMTPS id 15658385E021 for ; Thu, 21 Jan 2021 02:32:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 15658385E021 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=2ndquadrant.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=craig.ringer@2ndquadrant.com Received: by mail-lf1-x129.google.com with SMTP id b26so411315lff.9 for ; Wed, 20 Jan 2021 18:32:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=mime-version:from:date:message-id:subject:to; bh=0K6J46VhlVVXQUWu7d9WUWEoSnsJ0p88cS5Y0uu1Lbc=; b=R/zFCiD5C03XAK8UHpVooxRhBiQ1uXzFt21QUirMBeEMgisFUYtTywqOxhQtg11yIU kc18w8l2qUDFyaEEnkmraexKaBghL/lQT7cTxohgnehUnJ+ajIUVn2lGJQJFyqoKVsyv 7poeJpklRRsPnoVbM2i8ZOYJT8Pwl790PTOMefrXyiwSmeKXBTKTOFQEQUoG/5wfNgqd VYKBSkxMkGPQkZi3GpXxUEMuT7B4DzrHQrzJfjIOwVzP5gFD3lzFUquOQS9cNjRAEiBv aX6cH5e9QB8ixxl4cA0r/penANusUCJ45rXDhRcU/3HZEmcdeYAQs+VD2VHAo96un4O4 srHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=0K6J46VhlVVXQUWu7d9WUWEoSnsJ0p88cS5Y0uu1Lbc=; b=GRn2T5a8ATa1en7XwDW4R6WkdIwRaqORisCBfNzEBdgai0Kw7DQcCdxBHKpkU8e/f2 3F17tRVhepwqaBaN4ZI7u5q0jtBZBous0CytfaU9l+CSherJDEh8cOiROFWCS0dl0//5 zPc7HWW55ltXNRcYSPY/Qciim09hydWnftgIE82bOXk15nv9Q9cNCZ6UUYNw/x+ds/xj j0bVMGvzsjOhpO6OjfJiKywfejsTw10nhoQoJvrJtzPVqFqnaweOK3CVES9+lGgUFK9i U81Y/RsMFeFoWmm5ykWg4uxnGWOgS4NXpUF5bxaoxl1r1wt0eozCCT2YnyhUXiBI7/r9 p+Kw== X-Gm-Message-State: AOAM53095p7FFpjkBGH4dfhzHIMRQCaxrBvvqfcx13T2/YUGCJQgSZmX xqxQNO5dqi/OmmX32TpjNCTfaRAuzEtJeJyN+qVUueh3AP6fUuTe X-Google-Smtp-Source: ABdhPJyDBTZ4KZJgx739IDa3F/nX7N/ehgwCFkqKuur7CP6iIpepb+DNh5uFy/zaJHozLHI99md2A+HzE04NxKu4rEo= X-Received: by 2002:ac2:44da:: with SMTP id d26mr5069665lfm.221.1611196342389; Wed, 20 Jan 2021 18:32:22 -0800 (PST) MIME-Version: 1.0 From: Craig Ringer Date: Thu, 21 Jan 2021 10:32:11 +0800 Message-ID: Subject: Associative array "pop" ? To: systemtap@sourceware.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: systemtap@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Systemtap mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jan 2021 02:32:25 -0000 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