Changes between Version 12 and Version 13 of Libraries


Ignore:
Timestamp:
05/22/23 15:46:33 (3 years ago)
Author:
siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Libraries

    v12 v13  
    2828  * This function copies the data from the given bundle into the memory region starting at `ptr`.  The memory region extends for `$bundle_size(b)` bytes.
    2929* `$atomic_f void $bundle_unpack_apply($bundle data, void *buf, $operation op, int count, void *result)`
    30   * This function unpacks the bundle while applying the specified numeric operation. Parameter `op` specifies a binary operation.  For each ''i'' in 0..''count''-1, the operation is applied to the ''i''-th element of `buf` and the ''i''-th element of the bundle, and the result replaces the ''i''-th element of `buf`.  Parameter `count` is the number of elements in the bundle; `buf` should point to a region of memory with at least `count` elements.   The elements should all have the same numeric type.
     30  * This function unpacks the bundle while applying the specified numeric operation. Parameter `op` specifies a binary operation.  For each ''i'' in 0..''count''-1, the operation is applied to the ''i''-th element of `buf` and the ''i''-th element of the bundle, and the result is stored in the ''i''-th position of `result`.  Parameter `count` is the number of elements in the bundle; `buf` and `result` should each point to a region of memory capable of holding at least `count` elements.
     31
     32=== Example
     33{{{
     34#include <bundle.cvh>
     35int main() {
     36  int n = 10;
     37  int a[n], b[n], c[n];
     38  for (int i=0; i<n; i++) a[i] = i;
     39  $bundle bun = $bundle_pack(a, n*sizeof(int));
     40  $assert($bundle_size(bun) == n*sizeof(int));
     41  $bundle_unpack(bun, b);
     42  $assert($forall (int i: 0..n-1) b[i]==a[i]);
     43  $bundle_unpack_apply(bun, b, _SUM, n, c);
     44  $assert($forall (int i: 0..n-1) c[i]==2*a[i]);
     45}
     46}}}
    3147
    3248== comm