diff options
author | Robert Haas <rhaas@postgresql.org> | 2012-01-19 15:23:04 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2012-01-19 15:25:14 -0500 |
commit | cc53a1e7ccfa762bda70e1b6a15bfd929bf1b4e3 (patch) | |
tree | 22babcb206f440509a23d9ef22fd0970249d073a /src/backend | |
parent | 4f42b546fd87a80be30c53a0f2c897acb826ad52 (diff) | |
download | postgresql-cc53a1e7ccfa762bda70e1b6a15bfd929bf1b4e3.tar.gz postgresql-cc53a1e7ccfa762bda70e1b6a15bfd929bf1b4e3.zip |
Add bitwise AND, OR, and NOT operators for macaddr data type.
Brendan Jurd, reviewed by Fujii Masao
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/utils/adt/mac.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/backend/utils/adt/mac.c b/src/backend/utils/adt/mac.c index 333f4bca467..958ff54d73e 100644 --- a/src/backend/utils/adt/mac.c +++ b/src/backend/utils/adt/mac.c @@ -242,6 +242,59 @@ hashmacaddr(PG_FUNCTION_ARGS) } /* + * Arithmetic functions: bitwise NOT, AND, OR. + */ +Datum +macaddr_not(PG_FUNCTION_ARGS) +{ + macaddr *addr = PG_GETARG_MACADDR_P(0); + macaddr *result; + + result = (macaddr *) palloc(sizeof(macaddr)); + result->a = ~addr->a; + result->b = ~addr->b; + result->c = ~addr->c; + result->d = ~addr->d; + result->e = ~addr->e; + result->f = ~addr->f; + PG_RETURN_MACADDR_P(result); +} + +Datum +macaddr_and(PG_FUNCTION_ARGS) +{ + macaddr *addr1 = PG_GETARG_MACADDR_P(0); + macaddr *addr2 = PG_GETARG_MACADDR_P(1); + macaddr *result; + + result = (macaddr *) palloc(sizeof(macaddr)); + result->a = addr1->a & addr2->a; + result->b = addr1->b & addr2->b; + result->c = addr1->c & addr2->c; + result->d = addr1->d & addr2->d; + result->e = addr1->e & addr2->e; + result->f = addr1->f & addr2->f; + PG_RETURN_MACADDR_P(result); +} + +Datum +macaddr_or(PG_FUNCTION_ARGS) +{ + macaddr *addr1 = PG_GETARG_MACADDR_P(0); + macaddr *addr2 = PG_GETARG_MACADDR_P(1); + macaddr *result; + + result = (macaddr *) palloc(sizeof(macaddr)); + result->a = addr1->a | addr2->a; + result->b = addr1->b | addr2->b; + result->c = addr1->c | addr2->c; + result->d = addr1->d | addr2->d; + result->e = addr1->e | addr2->e; + result->f = addr1->f | addr2->f; + PG_RETURN_MACADDR_P(result); +} + +/* * Truncation function to allow comparing mac manufacturers. * From suggestion by Alex Pilosov <alex@pilosoft.com> */ |