From 844596c3d0c88a3c547db7ceb5be74ece05939ee Mon Sep 17 00:00:00 2001 From: programarivm Date: Thu, 26 Sep 2019 13:26:32 +0100 Subject: [PATCH] README update --- 03-databases/GenealogicalTree.m | 57 +++++++++++++++++++++++++++++++++ README.md | 16 +++++++++ 2 files changed, 73 insertions(+) create mode 100644 03-databases/GenealogicalTree.m diff --git a/03-databases/GenealogicalTree.m b/03-databases/GenealogicalTree.m new file mode 100644 index 0000000..505b34e --- /dev/null +++ b/03-databases/GenealogicalTree.m @@ -0,0 +1,57 @@ + +; global array as a tree + + w "Genealogical tree:",! + +; create global records + + s ^gtree(0)="Oliver" + s ^gtree(0,0)="Jack" + s ^gtree(0,1)="Amelia" + s ^gtree(0,0,0)="Harry" + s ^gtree(0,0,1)="Emily" + s ^gtree(0,1,0)="Thomas" + s ^gtree(0,1,1)="Jessica" + s ^gtree(0,0,0,0)="Michael" + s ^gtree(0,0,0,1)="Olivia" + s ^gtree(0,0,1,0)="Robert" + s ^gtree(0,0,1,1)="Mary" + s ^gtree(0,1,0,0)="George" + s ^gtree(0,1,0,1)="Susan" + s ^gtree(0,1,1,0)="Charles" + s ^gtree(0,1,1,1)="Elizabeth" +; ... + s ^gtree(0,0,0,0,0,0)="Thomas" + +; TODO: traverse the tree and display information +; ... + +; retrieve a global record + + w "^gtree(0,1,1) is ",^gtree(0,1,1),! + +; obtain data about a particular node +; 0, the node does not exist +; 1, the node exists, has no descendant +; 10, the node exists, has no data, has descendant +; 11, the node exists, has data, has descendant + + w "$data(^gtree(0,2)) is ",$data(^gtree(0,3)),! + w "$data(^gtree(0,1,1,1)) is ",$data(^gtree(0,1,1,1)),! + w "$data(^gtree(0,0,0,0,0)) is ",$data(^gtree(0,0,0,0,0)),! + w "$data(^gtree(0)) is ",$data(^gtree(0)),! + +; remove the global array +; 0, the node does not exist +; 0, the node does not exist +; 0, the node does not exist +; 0, the node does not exist + + w "Removing tree...",! + + k ^gtree + + w "$data(^gtree(0,2)) is ",$data(^gtree(0,3)),! + w "$data(^gtree(0,1,1,1)) is ",$data(^gtree(0,1,1,1)),! + w "$data(^gtree(0,0,0,0,0)) is ",$data(^gtree(0,0,0,0,0)),! + w "$data(^gtree(0)) is ",$data(^gtree(0)),! diff --git a/README.md b/README.md index 3553cef..69aa416 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,22 @@ Copy the examples into your `~/.fis-gtm/V6.3-003A_x86_64/r` folder and run: Enter n: 9 F(9) = 34 + +## 3. Databases + +### [`GenealogicalTree.m`](https://github.com/programarivm/mumps-examples/blob/master/02-user-defined-functions/GenealogicalTree.m) + + Genealogical tree: + ^gtree(0,1,1) is Jessica + $data(^gtree(0,2)) is 0 + $data(^gtree(0,1,1,1)) is 1 + $data(^gtree(0,0,0,0,0)) is 10 + $data(^gtree(0)) is 11 + Removing tree... + $data(^gtree(0,2)) is 0 + $data(^gtree(0,1,1,1)) is 0 + $data(^gtree(0,0,0,0,0)) is 0 + $data(^gtree(0)) is 0 --- ### Contributions