aboutsummaryrefslogtreecommitdiff
path: root/src/backend/nodes/list.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/nodes/list.c')
-rw-r--r--src/backend/nodes/list.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/backend/nodes/list.c b/src/backend/nodes/list.c
index 87dd3b6562b..f814047af43 100644
--- a/src/backend/nodes/list.c
+++ b/src/backend/nodes/list.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/list.c,v 1.26 1999/08/14 19:29:35 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/list.c,v 1.27 1999/08/16 02:17:42 tgl Exp $
*
* NOTES
* XXX a few of the following functions are duplicated to handle
@@ -448,6 +448,31 @@ intLispRemove(int elem, List *list)
#endif
/*
+ * ltruncate
+ * Truncate a list to n elements.
+ * Does nothing if n >= length(list).
+ * NB: the list is modified in-place!
+ */
+List *
+ltruncate(int n, List *list)
+{
+ List *ptr;
+
+ if (n <= 0)
+ return NIL; /* truncate to zero length */
+
+ foreach(ptr, list)
+ {
+ if (--n == 0)
+ {
+ lnext(ptr) = NIL;
+ break;
+ }
+ }
+ return list;
+}
+
+/*
* set_difference
*
* Return l1 without the elements in l2.