commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 02/14: pmt: adding pmt::dict_update(dict1,


From: git
Subject: [Commit-gnuradio] [gnuradio] 02/14: pmt: adding pmt::dict_update(dict1, dict2) function for merging dictionaries
Date: Fri, 9 May 2014 22:28:42 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit fd6feaf2885a635a21b5955897b9d85e141e460c
Author: Tim O'Shea <address@hidden>
Date:   Tue May 6 21:02:55 2014 -0400

    pmt: adding pmt::dict_update(dict1, dict2) function for merging dictionaries
---
 gnuradio-runtime/include/pmt/pmt.h |  3 +++
 gnuradio-runtime/lib/pmt/pmt.cc    | 13 +++++++++++++
 gnuradio-runtime/swig/pmt_swig.i   |  1 +
 3 files changed, 17 insertions(+)

diff --git a/gnuradio-runtime/include/pmt/pmt.h 
b/gnuradio-runtime/include/pmt/pmt.h
index 66cf1f7..3cae2f2 100644
--- a/gnuradio-runtime/include/pmt/pmt.h
+++ b/gnuradio-runtime/include/pmt/pmt.h
@@ -571,6 +571,9 @@ PMT_API pmt_t dict_items(pmt_t dict);
 //! Return list of keys
 PMT_API pmt_t dict_keys(pmt_t dict);
 
+//! Return a new dictionary \p dict1 with k=>v pairs from \p dict2 added.
+PMT_API pmt_t dict_update(const pmt_t &dict1, const pmt_t &dict2);
+
 //! Return list of values
 PMT_API pmt_t dict_values(pmt_t dict);
 
diff --git a/gnuradio-runtime/lib/pmt/pmt.cc b/gnuradio-runtime/lib/pmt/pmt.cc
index a9907ca..7760c02 100644
--- a/gnuradio-runtime/lib/pmt/pmt.cc
+++ b/gnuradio-runtime/lib/pmt/pmt.cc
@@ -813,6 +813,19 @@ dict_add(const pmt_t &dict, const pmt_t &key, const pmt_t 
&value)
 }
 
 pmt_t
+dict_update(const pmt_t &dict1, const pmt_t &dict2)
+{
+  pmt_t d(dict1);
+  pmt_t k(dict_keys(dict2));
+  while(is_pair(k)){
+    d = dict_add(d, car(k), dict_ref(dict2, car(k), PMT_NIL));
+    k = cdr(k);
+    }
+  return d;
+}
+
+
+pmt_t
 dict_delete(const pmt_t &dict, const pmt_t &key)
 {
   if (is_null(dict))
diff --git a/gnuradio-runtime/swig/pmt_swig.i b/gnuradio-runtime/swig/pmt_swig.i
index d05a0b4..2c0444f 100644
--- a/gnuradio-runtime/swig/pmt_swig.i
+++ b/gnuradio-runtime/swig/pmt_swig.i
@@ -239,6 +239,7 @@ namespace pmt{
   pmt_t dict_ref(const pmt_t &dict, const pmt_t &key, const pmt_t &not_found);
   pmt_t dict_items(pmt_t dict);
   pmt_t dict_keys(pmt_t dict);
+  pmt_t dict_update(const pmt_t &dict1, const pmt_t &dict2);
   pmt_t dict_values(pmt_t dict);
 
   bool is_any(pmt_t obj);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]