Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
tididi for C
Logo
tididi for C
  • 1. Your first circuit
  • 2. Choose valid configurations
  • 3. What are we counting?
  • 4. Evaluate probabilities
  • 5. Explore a directed graph
  • 6. Build and update a Boolean table
  • 7. Save related circuits
  • 8. Group related variables
  • 9. Ownership and errors
  • 10. Handle operation limits
  • 11. Find a cheapest configuration
  • 12. Inspect circuit size
  • 13. API reference
Back to top
View this page

7. Save related circuits¶

Save the shared vtree once and each circuit separately. In this example the two circuits are backup rules: local or remote storage, and remote implies encryption.

7.1. Serialize¶

The API returns owned text and byte buffers. Write the vtree text and each buffer to your preferred files or storage; use tididi_bytes_data and tididi_bytes_len to obtain the bytes. Serialization borrows the circuits.

char *vtree_text = NULL;
TididiBytes *first = NULL, *second = NULL;
check(tididi_vtree_to_text(vtree, &vtree_text));
check(tididi_to_bytes(destination, &first));
check(tididi_to_bytes(encryption, &second));

7.2. Restore one shared domain¶

Parse the vtree once, then load both circuits onto that same handle. They can then be combined immediately.

TididiVtree *restored = NULL;
TididiCircuit *left = NULL, *right = NULL, *rules = NULL;
check(tididi_vtree_from_text(vtree_text, &restored));
check(tididi_from_bytes(restored, tididi_bytes_data(first), tididi_bytes_len(first), &left));
check(tididi_from_bytes(restored, tididi_bytes_data(second), tididi_bytes_len(second), &right));
check(tididi_and(left, right, &rules, NULL));
printf("Restored valid configurations: %" PRIu64 "\n", count(rules));

Output:

Restored valid configurations: 4

7.3. Complete program¶

Download persistence.c and the shared helper. The source includes cleanup for all handles. Both files are included in the source checkout.

Next
8. Group related variables
Previous
6. Build and update a Boolean table
Copyright ©
Made with Sphinx and @pradyunsg's Furo
On this page
  • 7. Save related circuits
    • 7.1. Serialize
    • 7.2. Restore one shared domain
    • 7.3. Complete program