[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 09/13] value-labels: New function val_labs_find_value().
From: |
Ben Pfaff |
Subject: |
[PATCH 09/13] value-labels: New function val_labs_find_value(). |
Date: |
Mon, 16 Apr 2012 20:52:15 -0700 |
The new data sheet implementation (in an upcoming commit) will use
this.
---
src/data/value-labels.c | 31 ++++++++++++++++++++++++++++++-
src/data/value-labels.h | 4 +++-
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/src/data/value-labels.c b/src/data/value-labels.c
index 746e209..0b2ae3f 100644
--- a/src/data/value-labels.c
+++ b/src/data/value-labels.c
@@ -1,5 +1,5 @@
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2009, 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2009, 2010, 2011, 2012 Free Software
Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -256,6 +256,35 @@ val_labs_lookup (const struct val_labs *vls, const union
value *value)
return (vls == NULL ? NULL
: val_labs_lookup__ (vls, value, value_hash (value, vls->width, 0)));
}
+
+/* Searches VLS for a value label whose label is exactly LABEL. If successful,
+ returns the corresponding value. Otherwise, returns a null pointer.
+
+ Returns a null pointer if VLS is null.
+
+ This function is O(n) in the number of labels in VLS. */
+const union value *
+val_labs_find_value (const struct val_labs *vls, const char *label_)
+{
+ const union value *value = NULL;
+
+ if (vls != NULL)
+ {
+ const struct val_lab *vl;
+ const char *label;
+
+ label = intern_new (label_);
+ HMAP_FOR_EACH (vl, struct val_lab, node, &vls->labels)
+ if (vl->label == label)
+ {
+ value = &vl->value;
+ break;
+ }
+ intern_unref (label);
+ }
+
+ return value;
+}
/* Returns the first value label in VLS, in arbitrary order, or a
null pointer if VLS is empty or if VLS is a null pointer. If
diff --git a/src/data/value-labels.h b/src/data/value-labels.h
index f0f7ce0..af98d9f 100644
--- a/src/data/value-labels.h
+++ b/src/data/value-labels.h
@@ -1,5 +1,5 @@
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2009, 2011 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2009, 2011, 2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -93,6 +93,8 @@ size_t val_labs_count (const struct val_labs *);
const char *val_labs_find (const struct val_labs *, const union value *);
struct val_lab *val_labs_lookup (const struct val_labs *,
const union value *);
+const union value *val_labs_find_value (const struct val_labs *,
+ const char *label);
/* Basic properties. */
size_t val_labs_count (const struct val_labs *);
--
1.7.2.5
- Re: [PATCH 01/13] psppire-dict: g_return_if_fail for idx in psppire_dict_get_variable()., (continued)
[PATCH 02/13] gui: Use canonical names for signals., Ben Pfaff, 2012/04/16
[PATCH 03/13] gui: Add undocumented --measure-startup option., Ben Pfaff, 2012/04/16
[PATCH 04/13] gui: Call g_thread_init() earlier., Ben Pfaff, 2012/04/16
[PATCH 05/13] format: New functions fmt_change_width(), fmt_change_decimals()., Ben Pfaff, 2012/04/16
[PATCH 07/13] format: Fix typo in comment., Ben Pfaff, 2012/04/16
[PATCH 08/13] helper: New function value_to_text__()., Ben Pfaff, 2012/04/16
[PATCH 09/13] value-labels: New function val_labs_find_value().,
Ben Pfaff <=
[PATCH 06/13] format: Introduce a new type "enum fmt_use"., Ben Pfaff, 2012/04/16
[PATCH 10/13] abt: Drop child parameters from 'reaugment' function., Ben Pfaff, 2012/04/16
[PATCH 11/13] abt: New function abt_is_empty()., Ben Pfaff, 2012/04/16
[PATCH 12/13] range-set: Rename "insert" function "set1", "delete" to "set0"., Ben Pfaff, 2012/04/16
[PATCH 13/13] range-set: New macro RANGE_SET_FOR_EACH to make iteration easier., Ben Pfaff, 2012/04/16
Re: [PATCH 00/13] second batch of psppsheet changes, John Darrington, 2012/04/18