memory-graph 0.3.62__tar.gz → 0.3.64__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. {memory_graph-0.3.62/memory_graph.egg-info → memory_graph-0.3.64}/PKG-INFO +12 -7
  2. {memory_graph-0.3.62 → memory_graph-0.3.64}/README.md +11 -6
  3. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/__init__.py +1 -1
  4. {memory_graph-0.3.62 → memory_graph-0.3.64/memory_graph.egg-info}/PKG-INFO +12 -7
  5. memory_graph-0.3.64/memory_graph.egg-info/SOURCES.txt +39 -0
  6. {memory_graph-0.3.62 → memory_graph-0.3.64}/pyproject.toml +1 -1
  7. memory_graph-0.3.62/MANIFEST.in +0 -1
  8. memory_graph-0.3.62/images/add_one.png +0 -0
  9. memory_graph-0.3.62/images/add_one.py +0 -18
  10. memory_graph-0.3.62/images/avltree.py +0 -42
  11. memory_graph-0.3.62/images/avltree_dir.png +0 -0
  12. memory_graph-0.3.62/images/avltree_fail.png +0 -0
  13. memory_graph-0.3.62/images/avltree_key_value.png +0 -0
  14. memory_graph-0.3.62/images/avltree_leaf.png +0 -0
  15. memory_graph-0.3.62/images/avltree_linear.png +0 -0
  16. memory_graph-0.3.62/images/avltree_table.png +0 -0
  17. memory_graph-0.3.62/images/bin_search.png +0 -0
  18. memory_graph-0.3.62/images/bin_search.py +0 -40
  19. memory_graph-0.3.62/images/bin_search_linear.png +0 -0
  20. memory_graph-0.3.62/images/bin_tree.gif +0 -0
  21. memory_graph-0.3.62/images/bin_tree.png +0 -0
  22. memory_graph-0.3.62/images/bin_tree.py +0 -38
  23. memory_graph-0.3.62/images/binary.gif +0 -0
  24. memory_graph-0.3.62/images/binary.py +0 -14
  25. memory_graph-0.3.62/images/bitwise_operators.png +0 -0
  26. memory_graph-0.3.62/images/bitwise_operators.py +0 -39
  27. memory_graph-0.3.62/images/colab_example.png +0 -0
  28. memory_graph-0.3.62/images/copy_immutable.png +0 -0
  29. memory_graph-0.3.62/images/copy_immutable.py +0 -15
  30. memory_graph-0.3.62/images/copy_method.png +0 -0
  31. memory_graph-0.3.62/images/copy_method.py +0 -23
  32. memory_graph-0.3.62/images/copy_mix.png +0 -0
  33. memory_graph-0.3.62/images/copy_mix.py +0 -15
  34. memory_graph-0.3.62/images/copy_mutable.png +0 -0
  35. memory_graph-0.3.62/images/copy_mutable.py +0 -15
  36. memory_graph-0.3.62/images/create_gif.sh +0 -27
  37. memory_graph-0.3.62/images/create_images.sh +0 -47
  38. memory_graph-0.3.62/images/debug_vscode.png +0 -0
  39. memory_graph-0.3.62/images/debugging.gif +0 -0
  40. memory_graph-0.3.62/images/debugging.py +0 -13
  41. memory_graph-0.3.62/images/embedded1.png +0 -0
  42. memory_graph-0.3.62/images/embedded2.png +0 -0
  43. memory_graph-0.3.62/images/extension_numpy.png +0 -0
  44. memory_graph-0.3.62/images/extension_numpy.py +0 -15
  45. memory_graph-0.3.62/images/extension_pandas.png +0 -0
  46. memory_graph-0.3.62/images/extension_pandas.py +0 -17
  47. memory_graph-0.3.62/images/extension_torch.png +0 -0
  48. memory_graph-0.3.62/images/extension_torch.py +0 -10
  49. memory_graph-0.3.62/images/factorial.gif +0 -0
  50. memory_graph-0.3.62/images/factorial.py +0 -16
  51. memory_graph-0.3.62/images/hash_set.gif +0 -0
  52. memory_graph-0.3.62/images/hash_set.png +0 -0
  53. memory_graph-0.3.62/images/hash_set.py +0 -39
  54. memory_graph-0.3.62/images/hidden_edges.png +0 -0
  55. memory_graph-0.3.62/images/hidden_edges.py +0 -8
  56. memory_graph-0.3.62/images/immutable.py +0 -11
  57. memory_graph-0.3.62/images/immutable1.png +0 -0
  58. memory_graph-0.3.62/images/immutable2.png +0 -0
  59. memory_graph-0.3.62/images/introspect_depth.png +0 -0
  60. memory_graph-0.3.62/images/introspect_depth.py +0 -43
  61. memory_graph-0.3.62/images/ipython.png +0 -0
  62. memory_graph-0.3.62/images/jupyter_example.png +0 -0
  63. memory_graph-0.3.62/images/linked_list.gif +0 -0
  64. memory_graph-0.3.62/images/linked_list.png +0 -0
  65. memory_graph-0.3.62/images/linked_list.py +0 -35
  66. memory_graph-0.3.62/images/many_types.png +0 -0
  67. memory_graph-0.3.62/images/many_types.py +0 -13
  68. memory_graph-0.3.62/images/marimo_example.png +0 -0
  69. memory_graph-0.3.62/images/memory_graph_web_debugger.png +0 -0
  70. memory_graph-0.3.62/images/mutable.py +0 -11
  71. memory_graph-0.3.62/images/mutable1.png +0 -0
  72. memory_graph-0.3.62/images/mutable2.png +0 -0
  73. memory_graph-0.3.62/images/name_rebinding.py +0 -9
  74. memory_graph-0.3.62/images/not_node_types.py +0 -9
  75. memory_graph-0.3.62/images/power_set.gif +0 -0
  76. memory_graph-0.3.62/images/power_set.py +0 -26
  77. memory_graph-0.3.62/images/rebinding1.png +0 -0
  78. memory_graph-0.3.62/images/rebinding2.png +0 -0
  79. memory_graph-0.3.62/images/selection_sort.gif +0 -0
  80. memory_graph-0.3.62/images/sliding_puzzle.png +0 -0
  81. memory_graph-0.3.62/images/uva.png +0 -0
  82. memory_graph-0.3.62/images/vscode_copying.gif +0 -0
  83. memory_graph-0.3.62/images/wrap_int.png +0 -0
  84. memory_graph-0.3.62/images/wrap_int.py +0 -16
  85. memory_graph-0.3.62/memory_graph.egg-info/SOURCES.txt +0 -117
  86. {memory_graph-0.3.62 → memory_graph-0.3.64}/LICENSE.txt +0 -0
  87. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/call_stack.py +0 -0
  88. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/config.py +0 -0
  89. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/config_default.py +0 -0
  90. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/config_helpers.py +0 -0
  91. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/extension_numpy.py +0 -0
  92. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/extension_pandas.py +0 -0
  93. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/extension_torch.py +0 -0
  94. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/html_table.py +0 -0
  95. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/list_view.py +0 -0
  96. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/memory_to_nodes.py +0 -0
  97. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/node_base.py +0 -0
  98. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/node_key_value.py +0 -0
  99. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/node_leaf.py +0 -0
  100. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/node_linear.py +0 -0
  101. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/node_table.py +0 -0
  102. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/sequence.py +0 -0
  103. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/slicer.py +0 -0
  104. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/slices.py +0 -0
  105. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/slices_iterator.py +0 -0
  106. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/slices_table_iterator.py +0 -0
  107. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/test.py +0 -0
  108. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/test_max_graph_depth.py +0 -0
  109. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/test_memory_graph.py +0 -0
  110. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/test_memory_to_nodes.py +0 -0
  111. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/test_sequence.py +0 -0
  112. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/test_slicer.py +0 -0
  113. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/test_slices.py +0 -0
  114. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/test_slices_iterator.py +0 -0
  115. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph/utils.py +0 -0
  116. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph.egg-info/dependency_links.txt +0 -0
  117. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph.egg-info/requires.txt +0 -0
  118. {memory_graph-0.3.62 → memory_graph-0.3.64}/memory_graph.egg-info/top_level.txt +0 -0
  119. {memory_graph-0.3.62 → memory_graph-0.3.64}/setup.cfg +0 -0
  120. {memory_graph-0.3.62 → memory_graph-0.3.64}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memory_graph
3
- Version: 0.3.62
3
+ Version: 0.3.64
4
4
  Summary: Teaching tool and debugging aid in context of references, mutable data types, and shallow and deep copy.
5
5
  Author-email: Bas Terwijn <bterwijn@gmail.com>
6
6
  License-Expression: BSD-2-Clause
@@ -117,6 +117,10 @@ A better way to understand what values are shared is to draw a graph using [memo
117
117
 
118
118
  [Call Stack](#call-stack)
119
119
 
120
+ [Data Model Exercises](#data-model-exercises)
121
+
122
+ [Block](#block)
123
+
120
124
  [Debugging](#debugging)
121
125
 
122
126
  [Data Structure Examples](#data-structure-examples)
@@ -375,11 +379,11 @@ Or see it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=ht
375
379
 
376
380
  The effect of calling `add_one()` is that `b[0]` increases by 1, while `a` is unaffected.
377
381
 
378
- ## Exercises ##
382
+ # Data Model Exercises #
379
383
 
380
384
  Now is a good time to practice with Python Data Model concepts. Here are [some exercises](https://github.com/bterwijn/memory_graph_videos/blob/main/exercises/exercises.md) on references, mutability, copies, and function calls.
381
385
 
382
- ## Block ##
386
+ # Block #
383
387
  It is often helpful to temporarily block program execution to inspect the graph. For this we can use the `mg.block()` function:
384
388
 
385
389
  ```python
@@ -629,7 +633,7 @@ for i in range(n):
629
633
  Here we show values being inserted in a Binary Tree in Visual Studio Code. When inserting the last value '29' we "Step Into" the code to show the recursive implementation.
630
634
  ![images/bin_tree.gif](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/bin_tree.gif)
631
635
 
632
- Or see it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/bin_tree.py&timestep=0.2&play).
636
+ See it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/bin_tree.py&timestep=0.2&play) or see the more advanced [Multiway Tree](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/multiway_tree.py&breakpoints=19,33&continues=1&timestep=0.2&play) with more than two children per node, making the tree less deep and more efficient.
633
637
 
634
638
  ## Hash Set ##
635
639
  ```python
@@ -969,9 +973,10 @@ print('index:', index, 'data[index]:', data[index])
969
973
  Arguably the visualization is then more clear when we show a List_View object as an actual sublist using a Node_linear node:
970
974
 
971
975
  ```python
972
- mg.config.type_to_color[List_View] = 'hotpink'
973
- mg.config.type_to_node[List_View] = lambda data: mg.Node_Linear(data,
974
- data.lst[data.begin:data.end])
976
+ mg.config.type_to_node[List_View] = (lambda l: mg.Node_Linear(l,
977
+ [v if l.begin <= i < l.end else '' for i, v in enumerate(l.lst)]
978
+ if hasattr(l, 'end') else [])
979
+ )
975
980
  ```
976
981
  ![bin_search_linear.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/bin_search_linear.png)
977
982
 
@@ -97,6 +97,10 @@ A better way to understand what values are shared is to draw a graph using [memo
97
97
 
98
98
  [Call Stack](#call-stack)
99
99
 
100
+ [Data Model Exercises](#data-model-exercises)
101
+
102
+ [Block](#block)
103
+
100
104
  [Debugging](#debugging)
101
105
 
102
106
  [Data Structure Examples](#data-structure-examples)
@@ -355,11 +359,11 @@ Or see it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=ht
355
359
 
356
360
  The effect of calling `add_one()` is that `b[0]` increases by 1, while `a` is unaffected.
357
361
 
358
- ## Exercises ##
362
+ # Data Model Exercises #
359
363
 
360
364
  Now is a good time to practice with Python Data Model concepts. Here are [some exercises](https://github.com/bterwijn/memory_graph_videos/blob/main/exercises/exercises.md) on references, mutability, copies, and function calls.
361
365
 
362
- ## Block ##
366
+ # Block #
363
367
  It is often helpful to temporarily block program execution to inspect the graph. For this we can use the `mg.block()` function:
364
368
 
365
369
  ```python
@@ -609,7 +613,7 @@ for i in range(n):
609
613
  Here we show values being inserted in a Binary Tree in Visual Studio Code. When inserting the last value '29' we "Step Into" the code to show the recursive implementation.
610
614
  ![images/bin_tree.gif](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/bin_tree.gif)
611
615
 
612
- Or see it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/bin_tree.py&timestep=0.2&play).
616
+ See it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/bin_tree.py&timestep=0.2&play) or see the more advanced [Multiway Tree](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/multiway_tree.py&breakpoints=19,33&continues=1&timestep=0.2&play) with more than two children per node, making the tree less deep and more efficient.
613
617
 
614
618
  ## Hash Set ##
615
619
  ```python
@@ -949,9 +953,10 @@ print('index:', index, 'data[index]:', data[index])
949
953
  Arguably the visualization is then more clear when we show a List_View object as an actual sublist using a Node_linear node:
950
954
 
951
955
  ```python
952
- mg.config.type_to_color[List_View] = 'hotpink'
953
- mg.config.type_to_node[List_View] = lambda data: mg.Node_Linear(data,
954
- data.lst[data.begin:data.end])
956
+ mg.config.type_to_node[List_View] = (lambda l: mg.Node_Linear(l,
957
+ [v if l.begin <= i < l.end else '' for i, v in enumerate(l.lst)]
958
+ if hasattr(l, 'end') else [])
959
+ )
955
960
  ```
956
961
  ![bin_search_linear.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/bin_search_linear.png)
957
962
 
@@ -2,7 +2,7 @@
2
2
  # Copyright (c) 2023, Bas Terwijn.
3
3
  # SPDX-License-Identifier: BSD-2-Clause
4
4
 
5
- __version__ = "0.3.62"
5
+ __version__ = "0.3.64"
6
6
  __author__ = 'Bas Terwijn'
7
7
 
8
8
  import memory_graph.memory_to_nodes as memory_to_nodes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memory_graph
3
- Version: 0.3.62
3
+ Version: 0.3.64
4
4
  Summary: Teaching tool and debugging aid in context of references, mutable data types, and shallow and deep copy.
5
5
  Author-email: Bas Terwijn <bterwijn@gmail.com>
6
6
  License-Expression: BSD-2-Clause
@@ -117,6 +117,10 @@ A better way to understand what values are shared is to draw a graph using [memo
117
117
 
118
118
  [Call Stack](#call-stack)
119
119
 
120
+ [Data Model Exercises](#data-model-exercises)
121
+
122
+ [Block](#block)
123
+
120
124
  [Debugging](#debugging)
121
125
 
122
126
  [Data Structure Examples](#data-structure-examples)
@@ -375,11 +379,11 @@ Or see it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=ht
375
379
 
376
380
  The effect of calling `add_one()` is that `b[0]` increases by 1, while `a` is unaffected.
377
381
 
378
- ## Exercises ##
382
+ # Data Model Exercises #
379
383
 
380
384
  Now is a good time to practice with Python Data Model concepts. Here are [some exercises](https://github.com/bterwijn/memory_graph_videos/blob/main/exercises/exercises.md) on references, mutability, copies, and function calls.
381
385
 
382
- ## Block ##
386
+ # Block #
383
387
  It is often helpful to temporarily block program execution to inspect the graph. For this we can use the `mg.block()` function:
384
388
 
385
389
  ```python
@@ -629,7 +633,7 @@ for i in range(n):
629
633
  Here we show values being inserted in a Binary Tree in Visual Studio Code. When inserting the last value '29' we "Step Into" the code to show the recursive implementation.
630
634
  ![images/bin_tree.gif](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/bin_tree.gif)
631
635
 
632
- Or see it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/bin_tree.py&timestep=0.2&play).
636
+ See it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/bin_tree.py&timestep=0.2&play) or see the more advanced [Multiway Tree](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/multiway_tree.py&breakpoints=19,33&continues=1&timestep=0.2&play) with more than two children per node, making the tree less deep and more efficient.
633
637
 
634
638
  ## Hash Set ##
635
639
  ```python
@@ -969,9 +973,10 @@ print('index:', index, 'data[index]:', data[index])
969
973
  Arguably the visualization is then more clear when we show a List_View object as an actual sublist using a Node_linear node:
970
974
 
971
975
  ```python
972
- mg.config.type_to_color[List_View] = 'hotpink'
973
- mg.config.type_to_node[List_View] = lambda data: mg.Node_Linear(data,
974
- data.lst[data.begin:data.end])
976
+ mg.config.type_to_node[List_View] = (lambda l: mg.Node_Linear(l,
977
+ [v if l.begin <= i < l.end else '' for i, v in enumerate(l.lst)]
978
+ if hasattr(l, 'end') else [])
979
+ )
975
980
  ```
976
981
  ![bin_search_linear.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/bin_search_linear.png)
977
982
 
@@ -0,0 +1,39 @@
1
+ LICENSE.txt
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ memory_graph/__init__.py
6
+ memory_graph/call_stack.py
7
+ memory_graph/config.py
8
+ memory_graph/config_default.py
9
+ memory_graph/config_helpers.py
10
+ memory_graph/extension_numpy.py
11
+ memory_graph/extension_pandas.py
12
+ memory_graph/extension_torch.py
13
+ memory_graph/html_table.py
14
+ memory_graph/list_view.py
15
+ memory_graph/memory_to_nodes.py
16
+ memory_graph/node_base.py
17
+ memory_graph/node_key_value.py
18
+ memory_graph/node_leaf.py
19
+ memory_graph/node_linear.py
20
+ memory_graph/node_table.py
21
+ memory_graph/sequence.py
22
+ memory_graph/slicer.py
23
+ memory_graph/slices.py
24
+ memory_graph/slices_iterator.py
25
+ memory_graph/slices_table_iterator.py
26
+ memory_graph/test.py
27
+ memory_graph/test_max_graph_depth.py
28
+ memory_graph/test_memory_graph.py
29
+ memory_graph/test_memory_to_nodes.py
30
+ memory_graph/test_sequence.py
31
+ memory_graph/test_slicer.py
32
+ memory_graph/test_slices.py
33
+ memory_graph/test_slices_iterator.py
34
+ memory_graph/utils.py
35
+ memory_graph.egg-info/PKG-INFO
36
+ memory_graph.egg-info/SOURCES.txt
37
+ memory_graph.egg-info/dependency_links.txt
38
+ memory_graph.egg-info/requires.txt
39
+ memory_graph.egg-info/top_level.txt
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "memory_graph"
7
- version = "0.3.62"
7
+ version = "0.3.64"
8
8
  description = "Teaching tool and debugging aid in context of references, mutable data types, and shallow and deep copy."
9
9
  authors = [
10
10
  {name = "Bas Terwijn", email = "bterwijn@gmail.com"}
@@ -1 +0,0 @@
1
- recursive-include images/ *
Binary file
@@ -1,18 +0,0 @@
1
- # This file is part of memory_graph.
2
- # Copyright (c) 2023, Bas Terwijn.
3
- # SPDX-License-Identifier: BSD-2-Clause
4
-
5
- import memory_graph as mg
6
-
7
- def add_one(a, b, c):
8
- a += [1]
9
- b += (1,)
10
- c += [1]
11
- mg.render( mg.stack(), "add_one.png")
12
-
13
- a = [4, 3, 2]
14
- b = (4, 3, 2)
15
- c = [4, 3, 2]
16
-
17
- add_one(a, b, c.copy())
18
- print(f"a:{a} b:{b} c:{c}")
@@ -1,42 +0,0 @@
1
- # This file is part of memory_graph.
2
- # Copyright (c) 2023, Bas Terwijn.
3
- # SPDX-License-Identifier: BSD-2-Clause
4
-
5
- import memory_graph as mg
6
- import bintrees
7
-
8
- # Create an AVL tree
9
- tree = bintrees.AVLTree()
10
- tree.insert(10, "ten")
11
- tree.insert(5, "five")
12
- tree.insert(20, "twenty")
13
- tree.insert(15, "fifteen")
14
-
15
- # mg.render(locals(), 'avltree_fail.png') # id keeps changing
16
-
17
- mg.config.type_to_color[bintrees.avltree.Node] = "sandybrown"
18
- mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.Node_Linear(data, dir(data))
19
- mg.config.type_to_slicer[bintrees.avltree.Node] = mg.Slicer()
20
- # mg.render(locals(), 'avltree_dir.png') # stuff changes
21
-
22
- mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.Node_Leaf(data, f"key:{data.key} value:{data.value}")
23
- mg.render(locals(), 'avltree_leaf.png')
24
-
25
- mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.Node_Linear(data,
26
- ['left:', data.left,
27
- 'key:', data.key,
28
- 'value:', data.value,
29
- 'right:', data.right])
30
- mg.render(locals(), 'avltree_linear.png')
31
-
32
- mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.Node_Key_Value(data,
33
- {'left': data.left,
34
- 'key': data.key,
35
- 'value': data.value,
36
- 'right': data.right}.items())
37
- mg.render(locals(), 'avltree_key_value.png')
38
-
39
- mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.Node_Table(data,
40
- [[data.key, data.value],
41
- [data.left, data.right]])
42
- mg.render(locals(), 'avltree_table.png')
Binary file
Binary file
Binary file
Binary file
@@ -1,40 +0,0 @@
1
- import memory_graph as mg
2
- import random
3
- random.seed(2) # same random numbers each run
4
-
5
- class List_View:
6
-
7
- def __init__(self, lst, begin, end):
8
- self.lst = lst
9
- self.begin = begin
10
- self.end = end
11
-
12
- def __getitem__(self, index):
13
- return self.lst[index]
14
-
15
- def get_mid(self):
16
- return (self.begin + self.end) // 2
17
-
18
- def bin_search(view, value):
19
- mid = view.get_mid()
20
- if view.begin == mid:
21
- mg.render(mg.stack(), 'bin_search.png')
22
- mg.config.type_to_color[List_View] = 'hotpink'
23
- mg.config.type_to_node[List_View] = lambda data: mg.node_linear.Node_Linear(data,
24
- data.lst[data.begin:data.end] )
25
- mg.render(mg.stack(), 'bin_search_linear.png')
26
- return view.begin
27
- if value < view[mid]:
28
- return bin_search(List_View(view.lst, view.begin, mid), value)
29
- else:
30
- return bin_search(List_View(view.lst, mid, view.end), value)
31
-
32
- # create sorted list
33
- n = 15
34
- data = [random.randrange(1000) for _ in range(n)]
35
- data.sort()
36
-
37
- # search 'value'
38
- value = data[random.randrange(n)]
39
- index = bin_search(List_View(data, 0, len(data)), value)
40
- print('index:', index, 'data[index]:', data[index])
Binary file
Binary file
@@ -1,38 +0,0 @@
1
- # This file is part of memory_graph.
2
- # Copyright (c) 2023, Bas Terwijn.
3
- # SPDX-License-Identifier: BSD-2-Clause
4
-
5
- import memory_graph as mg
6
- import random
7
- random.seed(0) # use same random numbers each run
8
-
9
- class BinTree:
10
-
11
- def __init__(self, value=None, smaller=None, larger=None):
12
- self.smaller = smaller
13
- self.value = value
14
- self.larger = larger
15
-
16
- def add(self, value):
17
- if self.value is None:
18
- self.value = value
19
- elif value < self.value:
20
- if self.smaller is None:
21
- self.smaller = BinTree(value)
22
- else:
23
- self.smaller.add(value)
24
- else:
25
- if self.larger is None:
26
- self.larger = BinTree(value)
27
- else:
28
- self.larger.add(value)
29
- if value == 51:
30
- mg.render(mg.stack(), f"bin_tree.png")
31
- exit(0)
32
-
33
- tree = BinTree()
34
- n = 100
35
- for i in range(n):
36
- value = random.randrange(n)
37
- tree.add(value)
38
-
Binary file
@@ -1,14 +0,0 @@
1
- import memory_graph as mg
2
- import typing
3
- mg.config.type_to_horizontal[list] = True # horizontal lists
4
-
5
- def binary(value: int) -> typing.List[int]:
6
- mg.render(mg.stack(), 'binary.png', numbered=True)
7
- if value == 0:
8
- return []
9
- quotient, remainder = divmod(value, 2)
10
- result = binary(quotient) + [remainder]
11
- mg.render(mg.stack(), 'binary.png', numbered=True)
12
- return result
13
-
14
- print( binary(100) )
@@ -1,39 +0,0 @@
1
- import memory_graph as mg
2
-
3
- class Bits(dict):
4
- """ Dictionary subclass that we will configure to show binary representations. """
5
-
6
- def twos_complement(x: int, bits: int) -> str:
7
- """Return the two's complement bit string of x in `bits` bits."""
8
- mask = (1 << bits) - 1
9
- return format(x & mask, f"0{bits}b")
10
-
11
- # configure memory_graph to show binary representations of values of type Bits
12
- mg.config.type_to_node[Bits] = lambda x : mg.Node_Table(x,
13
- [ ["expression", "decimal", "bin(expression)", "16bit two's complement"] ] +
14
- [ [k, f'{v:>10}', f'{bin(v):>19}', twos_complement(v,16)] for k, v in x.items()] )
15
- mg.config.type_to_slicer[Bits] = (mg.Slicer(), mg.Slicer()) # no slicing
16
- mg.config.type_to_color[Bits] = 'gold'
17
- mg.config.fontname = 'Courier' # monospace font
18
-
19
- bits = Bits()
20
-
21
- # now add some some variables and expressions
22
- bits['a'] = 1
23
- bits['b'] = 48
24
- bits['c'] = 127
25
- bits['a << 3'] = bits['a'] << 3 # bit shift left by 3
26
- bits['b >> 3'] = bits['b'] >> 3 # bit shift right by 3
27
- bits['a | b'] = bits['a'] | bits['b'] # bitwise or
28
- bits['b & c'] = bits['b'] & bits['c'] # bitwise and
29
- bits['b ^ c'] = bits['b'] ^ bits['c'] # bitwise exclusive or
30
-
31
- # negative numbers, inverse, and two's complement
32
- bits['d'] = 240
33
- bits['e'] = -240
34
- bits['f'] = -241 # -(d+1)
35
- bits['~d'] = ~ bits['d'] # inverse -(x+1)
36
- bits['~e'] = ~ bits['e'] # inverse -(x+1)
37
- bits['~f'] = ~ bits['f'] # inverse -(x+1)
38
-
39
- mg.render(locals(), 'bitwise_operators.png')
@@ -1,15 +0,0 @@
1
- # This file is part of memory_graph.
2
- # Copyright (c) 2023, Bas Terwijn.
3
- # SPDX-License-Identifier: BSD-2-Clause
4
-
5
- import memory_graph as mg
6
- import copy
7
-
8
- a = ( (1, 2), ('x', 'y') ) # a nested tuple
9
-
10
- # three different ways to make a "copy" of 'a':
11
- c1 = a
12
- c2 = copy.copy(a)
13
- c3 = copy.deepcopy(a)
14
-
15
- mg.render(locals(), 'copy_immutable.png')
Binary file
@@ -1,23 +0,0 @@
1
- # This file is part of memory_graph.
2
- # Copyright (c) 2023, Bas Terwijn.
3
- # SPDX-License-Identifier: BSD-2-Clause
4
-
5
- import memory_graph as mg
6
- import copy
7
-
8
- class My_Class:
9
-
10
- def __init__(self):
11
- self.digits = [1, 2]
12
- self.letters = ['x', 'y']
13
-
14
- def custom_copy(self):
15
- """ Copies 'digits' but shares 'letters'. """
16
- c = copy.copy(self)
17
- c.digits = copy.copy(self.digits)
18
- return c
19
-
20
- a = My_Class()
21
- b = a.custom_copy()
22
-
23
- mg.render(locals(), 'copy_method.png')
Binary file
@@ -1,15 +0,0 @@
1
- # This file is part of memory_graph.
2
- # Copyright (c) 2023, Bas Terwijn.
3
- # SPDX-License-Identifier: BSD-2-Clause
4
-
5
- import memory_graph as mg
6
- import copy
7
-
8
- a = ( [1, 2], ('x', 'y') ) # mix of mutable and immutable
9
-
10
- # three different ways to make a "copy" of 'a':
11
- c1 = a
12
- c2 = copy.copy(a)
13
- c3 = copy.deepcopy(a)
14
-
15
- mg.render(locals(), 'copy_mix.png')
Binary file
@@ -1,15 +0,0 @@
1
- # This file is part of memory_graph.
2
- # Copyright (c) 2023, Bas Terwijn.
3
- # SPDX-License-Identifier: BSD-2-Clause
4
-
5
- import memory_graph as mg
6
- import copy
7
-
8
- a = [ [1, 2], ['x', 'y'] ] # a nested list (a list containing lists)
9
-
10
- # three different ways to make a "copy" of 'a':
11
- c1 = a
12
- c2 = copy.copy(a) # equivalent to: a.copy() a[:] list(a)
13
- c3 = copy.deepcopy(a)
14
-
15
- mg.render(locals(), 'copy_mutable.png')
@@ -1,27 +0,0 @@
1
- #!/bin/bash
2
- #
3
- # install:
4
- #
5
- # sudo apt install imagemagick
6
-
7
- name="$1"
8
- files=$(ls -v $name*.png | tr '\n' ' ')
9
- files_gv=$(ls -v $name*.gv | tr '\n' ' ')
10
- echo "creating gif with:"
11
- echo "$files"
12
-
13
- largest_size=$(identify -format "%H %Wx%H %f\n" $name*.png | sort -nr | head -n1| awk '{print $2}')
14
- echo "largest_size: $largest_size"
15
-
16
- echo "resizing images"
17
- mogrify -resize $largest_size -background white -gravity center -extent $largest_size $files
18
-
19
- echo "creating file: $name.gif"
20
- convert -delay 150 -dither None -loop 0 $files $name.gif
21
-
22
- if [ "$2" = "-d" ]; then
23
- echo "deleting: $files $files_gv"
24
- rm $files $files_gv
25
- fi
26
-
27
- echo "done"
@@ -1,47 +0,0 @@
1
- # intro
2
- python many_types.py
3
-
4
- # debugging
5
- python debugging.py
6
- bash create_gif.sh debugging -d
7
-
8
- # data model
9
- python immutable.py
10
- python mutable.py
11
- python copy_mutable.py
12
- python copy_method.py
13
- python copy_immutable.py
14
- python copy_mix.py
15
- python name_rebinding.py
16
-
17
- # call stack
18
- python add_one.py
19
- python wrap_int.py
20
- python factorial.py
21
- bash create_gif.sh factorial -d
22
- python binary.py
23
- bash create_gif.sh binary -d
24
- python power_set.py
25
- bash create_gif.sh power_set -d
26
-
27
- # datastructures
28
- python linked_list.py
29
- python bin_tree.py
30
- python hash_set.py
31
-
32
- # configuration
33
- python not_node_types.py
34
-
35
- # introspection
36
- python avltree.py
37
- python bin_search.py
38
- python bitwise_operators.py
39
- python introspect_depth.py
40
- python hidden_edges.py
41
-
42
- # extensions
43
- python extension_numpy.py
44
- python extension_pandas.py
45
-
46
- # clean up the graphviz files
47
- rm *.gv
Binary file
Binary file
@@ -1,13 +0,0 @@
1
- # This file is part of memory_graph.
2
- # Copyright (c) 2023, Bas Terwijn.
3
- # SPDX-License-Identifier: BSD-2-Clause
4
-
5
- import memory_graph as mg
6
-
7
- squares = []
8
- squares_collector = []
9
- for i in range(1,6):
10
- squares.append(i**2)
11
- squares_collector.append(squares.copy())
12
- mg.render(locals(), 'debugging.png', numbered=True)
13
- mg.render(locals(), 'debugging.png', numbered=True)
Binary file
Binary file