From 3343f07e43ec26548b22d5d49fc6d6bb4be2a744 Mon Sep 17 00:00:00 2001 From: Bernat Romagosa Date: Tue, 8 Feb 2022 10:25:52 +0100 Subject: [PATCH] Bitwise operators library --- libraries/LIBRARIES | 1 + libraries/bitwise.js | 48 +++++++++++++++++++++++++++++++++++++++++++ libraries/bitwise.xml | 1 + 3 files changed, 50 insertions(+) create mode 100644 libraries/bitwise.js create mode 100644 libraries/bitwise.xml diff --git a/libraries/LIBRARIES b/libraries/LIBRARIES index 99f9e9c0..46de14f8 100644 --- a/libraries/LIBRARIES +++ b/libraries/LIBRARIES @@ -29,6 +29,7 @@ stream-tools.xml Streams (lazy lists) A variation on the list data type in which bar-charts.xml Bar charts Takes a table (typically from a CSV data set) as input and reports a summary of the table grouped by the field in the specified column number. The remaining three inputs are used only if the field values are numbers, in which case they can be grouped into buckets (e.g., decades, centuries, etc.). Those three inputs specify the smallest and largest values of interest and, most importantly, the width of a bucket (10 for decades, 100 for centuries). If the field isn't numeric, leave these three inputs empty or set them to zero. In that case, each string value of the field is its own bucket, and they appear sorted alphabetically. The block reports a new table with three columns. The first column contains the bucket name or smallest number. The second column contains a nonnegative integer that says how many records in the input table fall into this bucket. The third column is a subtable containing the actual records from the original table that fall into the bucket. If your buckets aren't of constant width, or you want to group by some function of more than one field, load the "Frequency Distribution Analysis" library instead. httpBlocks.xml Web services access (https) An extended version of the URL block that allows POST, PUT, and DELETE as well as GET requests, allows using the secure HTTPS protocol, and gives control over headers, etc. Also parses JSON data. make-variables.xml Create variables Create and manage global/sprite/script variables in a script +bitwise.xml Bitwise operators Bitwise arithmetic operators for low-level bit manipulation. ~ ~ ~ ~ ~ ~ diff --git a/libraries/bitwise.js b/libraries/bitwise.js new file mode 100644 index 00000000..da5ece5f --- /dev/null +++ b/libraries/bitwise.js @@ -0,0 +1,48 @@ +SnapExtensions.primitives.set( + 'bit_and(a, b)', + function (a, b) { + return a & b; + } +); + +SnapExtensions.primitives.set( + 'bit_or(a, b)', + function (a, b) { + return a | b; + } +); + +SnapExtensions.primitives.set( + 'bit_xor(a, b)', + function (a, b) { + return a ^ b; + } +); + +SnapExtensions.primitives.set( + 'bit_not(a)', + function (a) { + return ~ a; + } +); + +SnapExtensions.primitives.set( + 'bit_left_shift(a, b)', + function (a, b) { + return a << b; + } +); + +SnapExtensions.primitives.set( + 'bit_right_shift(a, b)', + function (a, b) { + return a >> b; + } +); + +SnapExtensions.primitives.set( + 'bit_unsigned_right_shift(a, b)', + function (a, b) { + return a >>> b; + } +); diff --git a/libraries/bitwise.xml b/libraries/bitwise.xml new file mode 100644 index 00000000..324b1a57 --- /dev/null +++ b/libraries/bitwise.xml @@ -0,0 +1 @@ +
\ No newline at end of file