Bruce,
please find attached patch to current CVS ( contrib/ltree )
Changes:
July 31, 2002
Now works on 64-bit platforms.
Added function lca - lowest common ancestor
Version for 7.2 is distributed as separate package -
http://www.sai.msu.su/~megera/postgres/gist/ltree/ltree-7.2.tar.gz
Regards,
Oleg
_
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: [EMAIL PROTECTED], http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83
Common subdirectories: contrib/ltree.old/CVS and contrib/ltree/CVS
diff -c contrib/ltree.old/README.ltree contrib/ltree/README.ltree
*** contrib/ltree.old/README.ltree Tue Jul 30 20:40:34 2002
--- contrib/ltree/README.ltree Wed Jul 31 21:38:07 2002
***
*** 4,10
types, indexed access methods and queries for data organized as a tree-like
structures.
This module will works for PostgreSQL version 7.3.
! (patch for 7.2 version is provided, see INSTALLATION)
---
All work was done by Teodor Sigaev ([EMAIL PROTECTED]) and Oleg Bartunov
([EMAIL PROTECTED]). See http://www.sai.msu.su/~megera/postgres/gist for
--- 4,10
types, indexed access methods and queries for data organized as a tree-like
structures.
This module will works for PostgreSQL version 7.3.
! (version for 7.2 version is available from
http://www.sai.msu.su/~megera/postgres/gist/ltree/ltree-7.2.tar.gz)
---
All work was done by Teodor Sigaev ([EMAIL PROTECTED]) and Oleg Bartunov
([EMAIL PROTECTED]). See http://www.sai.msu.su/~megera/postgres/gist for
***
*** 184,192
nlevel
3
!
! Note, that arguments start, end, OFFSET, LEN have meaning of level of the node
! !
INSTALLATION
--- 184,204
nlevel
3
! Note, that arguments start, end, OFFSET, LEN have meaning of level of the
! node !
!
! ltree lca(ltree,ltree,...) (up to 8 arguments)
! ltree lca(ltree[])
! Returns Lowest Common Ancestor (lca)
! # select lca('1.2.2.3','1.2.3.4.5.6');
! lca
! -
! 1.2
! # select lca('{la.2.3,1.2.3.4.5.6}') is null;
! ?column?
! --
! f
!
INSTALLATION
***
*** 195,202
make install
make installcheck
- for 7.2 one needs to apply patch ( patch patch.72) before installation !
-
EXAMPLE OF USAGE
createdb ltreetest
--- 207,212
***
*** 416,421
--- 426,436
CHANGES
+ July 31, 2002
+Now works on 64-bit platforms.
+Added function lca - lowest common ancestor
+Version for 7.2 is distributed as separate package -
+http://www.sai.msu.su/~megera/postgres/gist/ltree/ltree-7.2.tar.gz
July 13, 2002
Initial release.
diff -c contrib/ltree.old/_ltree_op.c contrib/ltree/_ltree_op.c
*** contrib/ltree.old/_ltree_op.c Tue Jul 30 20:40:34 2002
--- contrib/ltree/_ltree_op.c Wed Jul 31 21:31:47 2002
***
*** 28,33
--- 28,35
Datum _ltq_extract_regex(PG_FUNCTION_ARGS);
Datum _ltxtq_extract_exec(PG_FUNCTION_ARGS);
+ PG_FUNCTION_INFO_V1(_lca);
+ Datum _lca(PG_FUNCTION_ARGS);
typedef Datum (*PGCALL2)(PG_FUNCTION_ARGS);
#define NEXTVAL(x) ( (ltree*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) )
***
*** 208,212
--- 210,238
PG_FREE_IF_COPY(la,0);
PG_FREE_IF_COPY(query,1);
PG_RETURN_POINTER(item);
+ }
+
+ Datum
+ _lca(PG_FUNCTION_ARGS) {
+ ArrayType *la = (ArrayType
+*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0)));
+ int num=ArrayGetNItems( ARR_NDIM(la), ARR_DIMS(la));
+ ltree *item = (ltree*)ARR_DATA_PTR(la);
+ ltree **a,*res;
+
+ a=(ltree**)palloc( sizeof(ltree*) * num );
+ while( num0 ) {
+ num--;
+ a[num] = item;
+ item = NEXTVAL(item);
+ }
+ res = lca_inner(a, ArrayGetNItems( ARR_NDIM(la), ARR_DIMS(la)));
+ pfree(a);
+
+ PG_FREE_IF_COPY(la,0);
+
+ if ( res )
+ PG_RETURN_POINTER(res);
+ else
+ PG_RETURN_NULL();
}
Common subdirectories: contrib/ltree.old/data and contrib/ltree/data
Common subdirectories: contrib/ltree.old/expected and contrib/ltree/expected
diff -c contrib/ltree.old/ltree.h contrib/ltree/ltree.h
*** contrib/ltree.old/ltree.h Tue Jul 30 20:40:34 2002
--- contrib/ltree/ltree.h Wed Jul 31 21:31:47 2002
***
*** 12,18
} ltree_level;