Skip to content

Commit

Permalink
examples: fix typos (#18229)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed May 25, 2023
1 parent caee393 commit 993546a
Show file tree
Hide file tree
Showing 28 changed files with 89 additions and 89 deletions.
2 changes: 1 addition & 1 deletion examples/binary_search_tree.v
Expand Up @@ -76,7 +76,7 @@ fn (tree Tree[T]) min[T]() T {
}
}

// delete a value in BST (if nonexistant do nothing)
// delete a value in BST (if nonexistent do nothing)
fn (tree Tree[T]) delete[T](x T) Tree[T] {
return match tree {
Empty {
Expand Down
12 changes: 6 additions & 6 deletions examples/graphs/bellman-ford.v
@@ -1,11 +1,11 @@
/*
A V program for Bellman-Ford's single source
shortest path algorithm.
literaly adapted from:
literally adapted from:
https://www.geeksforgeeks.org/bellman-ford-algorithm-dp-23/
// Adapted from this site... from C++ and Python codes
For Portugese reference
For Portuguese reference
http://rascunhointeligente.blogspot.com/2010/10/o-algoritmo-de-bellman-ford-um.html
code by CCS
Expand All @@ -24,7 +24,7 @@ mut:
// building a map of with all edges etc of a graph, represented from a matrix adjacency
// Input: matrix adjacency --> Output: edges list of src, dest and weight
fn build_map_edges_from_graph[T](g [][]T) map[T]EDGE {
n := g.len // TOTAL OF NODES for this graph -- its dimmension
n := g.len // TOTAL OF NODES for this graph -- its dimensions
mut edges_map := map[int]EDGE{} // a graph represented by map of edges

mut edge := 0 // a counter of edges
Expand Down Expand Up @@ -61,8 +61,8 @@ fn bellman_ford[T](graph [][]T, src int) {
// Step 1: Initialize distances from src to all other
// vertices as INFINITE
n_vertex := graph.len // adjc matrix ... n nodes or vertex
mut dist := []int{len: n_vertex, init: large} // dist with -1 instead of INIFINITY
// mut path := []int{len: n , init:-1} // previous node of each shortest paht
mut dist := []int{len: n_vertex, init: large} // dist with -1 instead of INFINITY
// mut path := []int{len: n , init:-1} // previous node of each shortest path
dist[src] = 0

// Step 2: Relax all edges |V| - 1 times. A simple
Expand Down Expand Up @@ -152,7 +152,7 @@ fn main() {
// for index, g_value in [graph_01, graph_02, graph_03] {
for index, g_value in [graph_01, graph_02, graph_03] {
graph = g_value.clone() // graphs_sample[g].clone() // choice your SAMPLE
// allways starting by node 0
// always starting by node 0
start_node := 0
println('\n\n Graph ${index + 1} using Bellman-Ford algorithm (source node: ${start_node})')
bellman_ford(graph, start_node)
Expand Down
6 changes: 3 additions & 3 deletions examples/graphs/bfs2.v
@@ -1,7 +1,7 @@
// Author: CCS
// I follow literally code in C, done many years ago
fn main() {
// Adjacency matrix as a map
// Adjacency matrix as a map
graph := {
'A': ['B', 'C']
'B': ['A', 'D', 'E']
Expand Down Expand Up @@ -37,7 +37,7 @@ fn breadth_first_search_path(graph map[string][]string, start string, target str
// Expansion of node removed from queue
print('\n Expansion of node ${node} (true/false): ${graph[node]}')
// take all nodes from the node
for vertex in graph[node] { // println("\n ...${vertex}")
for vertex in graph[node] { // println("\n ...${vertex}")
// not explored yet
if visited[vertex] == false {
queue << vertex
Expand Down Expand Up @@ -79,7 +79,7 @@ fn build_path_reverse(graph map[string][]string, start string, final string, vis
for i in array_of_nodes {
if current in graph[i] && visited[i] == true {
current = i
break // the first ocurrence is enough
break // the first occurrence is enough
}
}
path << current // update the path tracked
Expand Down
6 changes: 3 additions & 3 deletions examples/graphs/dfs.v
Expand Up @@ -2,7 +2,7 @@
// I follow literally code in C, done many years ago

fn main() {
// Adjacency matrix as a map
// Adjacency matrix as a map
// Example 01
graph_01 := {
'A': ['B', 'C']
Expand Down Expand Up @@ -44,7 +44,7 @@ fn depth_first_search_path(graph map[string][]string, start string, target strin

// check if this node is already visited
if visited[node] == false {
// if no ... test it searchin for a final node
// if no ... test it and search for a final node
visited[node] = true // means: node visited
if node == target {
path = build_path_reverse(graph, start, node, visited)
Expand Down Expand Up @@ -93,7 +93,7 @@ fn build_path_reverse(graph map[string][]string, start string, final string, vis
for i in array_of_nodes {
if current in graph[i] && visited[i] == true {
current = i
break // the first ocurrence is enough
break // the first occurrence is enough
}
}
path << current // updating the path tracked
Expand Down
22 changes: 11 additions & 11 deletions examples/graphs/dijkstra.v
Expand Up @@ -22,7 +22,7 @@ $ ./an_executable.EXE
Code based from : Data Structures and Algorithms Made Easy: Data Structures and Algorithmic Puzzles, Fifth Edition (English Edition)
pseudo code written in C
This idea is quite different: it uses a priority queue to store the current
shortest path evaluted
shortest path evaluated
The priority queue structure built using a list to simulate
the queue. A heap is not used in this case.
*/
Expand All @@ -38,17 +38,17 @@ mut:
// The "push" always sorted in pq
fn push_pq[T](mut prior_queue []T, data int, priority int) {
mut temp := []T{}
lenght_pq := prior_queue.len
pq_len := prior_queue.len

mut i := 0
for i < lenght_pq && priority > prior_queue[i].priority {
for i < pq_len && priority > prior_queue[i].priority {
temp << prior_queue[i]
i++
}
// INSERTING SORTED in the queue
temp << NODE{data, priority} // do the copy in the right place
// copy the another part (tail) of original prior_queue
for i < lenght_pq {
for i < pq_len {
temp << prior_queue[i]
i++
}
Expand All @@ -59,16 +59,16 @@ fn push_pq[T](mut prior_queue []T, data int, priority int) {
// Change the priority of a value/node ... exist a value, change its priority
fn updating_priority[T](mut prior_queue []T, search_data int, new_priority int) {
mut i := 0
mut lenght_pq := prior_queue.len
mut pq_len := prior_queue.len

for i < lenght_pq {
for i < pq_len {
if search_data == prior_queue[i].data {
prior_queue[i] = NODE{search_data, new_priority} // do the copy in the right place
prior_queue[i] = NODE{search_data, new_priority} // do the copy in the right place
break
}
i++
// all the list was examined
if i >= lenght_pq {
if i >= pq_len {
print('\n This data ${search_data} does exist ... PRIORITY QUEUE problem\n')
exit(1) // panic(s string)
}
Expand Down Expand Up @@ -126,7 +126,7 @@ fn dijkstra(g [][]int, s int) {
mut n := g.len

mut dist := []int{len: n, init: -1} // dist with -1 instead of INIFINITY
mut path := []int{len: n, init: -1} // previous node of each shortest paht
mut path := []int{len: n, init: -1} // previous node of each shortest path

// Distance of source vertex from itself is always 0
dist[s] = 0
Expand Down Expand Up @@ -223,13 +223,13 @@ fn main() {
[5, 15, 4, 0],
]

// To find number of coluns
// To find number of columns
// mut cols := an_array[0].len
mut graph := [][]int{} // the graph: adjacency matrix
// for index, g_value in [graph_01, graph_02, graph_03] {
for index, g_value in [graph_01, graph_02, graph_03] {
graph = g_value.clone() // graphs_sample[g].clone() // choice your SAMPLE
// allways starting by node 0
// always starting by node 0
start_node := 0
println('\n\n Graph ${index + 1} using Dijkstra algorithm (source node: ${start_node})')
dijkstra(graph, start_node)
Expand Down
22 changes: 11 additions & 11 deletions examples/graphs/minimal_spann_tree_prim.v
Expand Up @@ -16,7 +16,7 @@ $ ./an_executable.EXE
Code based from : Data Structures and Algorithms Made Easy: Data Structures and Algorithmic Puzzles, Fifth Edition (English Edition)
pseudo code written in C
This idea is quite different: it uses a priority queue to store the current
shortest path evaluted
shortest path evaluated
The priority queue structure built using a list to simulate
the queue. A heap is not used in this case.
*/
Expand All @@ -32,17 +32,17 @@ mut:
// The "push" always sorted in pq
fn push_pq[T](mut prior_queue []T, data int, priority int) {
mut temp := []T{}
lenght_pq := prior_queue.len
pg_len := prior_queue.len

mut i := 0
for i < lenght_pq && priority > prior_queue[i].priority {
for i < pg_len && priority > prior_queue[i].priority {
temp << prior_queue[i]
i++
}
// INSERTING SORTED in the queue
temp << NODE{data, priority} // do the copy in the right place
// copy the another part (tail) of original prior_queue
for i < lenght_pq {
for i < pg_len {
temp << prior_queue[i]
i++
}
Expand All @@ -52,17 +52,17 @@ fn push_pq[T](mut prior_queue []T, data int, priority int) {
// Change the priority of a value/node ... exist a value, change its priority
fn updating_priority[T](mut prior_queue []T, search_data int, new_priority int) {
mut i := 0
mut lenght_pq := prior_queue.len
mut pg_len := prior_queue.len

for i < lenght_pq {
for i < pg_len {
if search_data == prior_queue[i].data {
prior_queue[i] = NODE{search_data, new_priority} // do the copy in the right place
prior_queue[i] = NODE{search_data, new_priority} // do the copy in the right place
break
}
i++
// all the list was examined
if i >= lenght_pq {
// print('\n Priority Queue: ${prior_queue}')
if i >= pg_len {
// print('\n Priority Queue: ${prior_queue}')
// print('\n These data ${search_data} and ${new_priority} do not exist ... PRIORITY QUEUE problem\n')
// if it does not find ... then push it
push_pq(mut prior_queue, search_data, new_priority)
Expand Down Expand Up @@ -118,7 +118,7 @@ fn prim_mst(g [][]int, s int) {
mut n := g.len

mut dist := []int{len: n, init: -1} // dist with -1 instead of INIFINITY
mut path := []int{len: n, init: -1} // previous node of each shortest paht
mut path := []int{len: n, init: -1} // previous node of each shortest path

// Distance of source vertex from itself is always 0
dist[s] = 0
Expand Down Expand Up @@ -216,7 +216,7 @@ fn main() {
for index, g_value in [graph_01, graph_02, graph_03] {
println('\n Minimal Spanning Tree of graph ${index + 1} using PRIM algorithm')
graph = g_value.clone() // graphs_sample[g].clone() // choice your SAMPLE
// starting by node x ... see the graphs dimmension
// starting by node x ... see the graphs dimensions
start_node := 0
prim_mst(graph, start_node)
}
Expand Down
6 changes: 3 additions & 3 deletions examples/graphs/topological_sorting_greedy.v
Expand Up @@ -11,9 +11,9 @@ fn topog_sort_greedy(graph map[string][]string) []string {
mut top_order := []string{} // a vector with sequence of nodes visited
mut count := 0
/*
IDEA ( a greedy algorythm ):
IDEA ( a greedy algorithm ):
1. choose allways the node with smallest input degree
1. choose always the node with smallest input degree
2. visit it
3. put it in the output vector
4. remove it from graph
Expand Down Expand Up @@ -94,7 +94,7 @@ fn remove_node_from_graph(node string, a_map map[string][]string) map[string][]s
mut all_nodes := new_graph.keys() // get all nodes of this graph
// FOR THE FUTURE with filter
// for i in all_nodes {
// new_graph[i] = new_graph[i].filter(index(it) != node)
// new_graph[i] = new_graph[i].filter(index(it) != node)
// }
// A HELP FROM V discussion GITHUB - thread
for key in all_nodes {
Expand Down
2 changes: 1 addition & 1 deletion examples/js_dom_draw_bechmark_chart/chart/main.v
Expand Up @@ -197,7 +197,7 @@ fn gen_table_info(attribute_names []string, framework_platform map[string][]int)
// qtd. of values in 10 % of arrays
ten_perc := int(framework_platform[name].len / 10)

// get 10% highter
// get 10% higher
mut min_ten_array := framework_platform[name].clone()
min_ten_array.sort()
min_ten_array.trim(ten_perc)
Expand Down
4 changes: 2 additions & 2 deletions examples/path_tracing.v
Expand Up @@ -161,7 +161,7 @@ fn (sp Sphere) intersect(r Ray) f64 {
* 0) Cornell Box with 2 spheres
* 1) Sunset
* 2) Psychedelic
* The sphere fileds are: Sphere{radius, position, emission, color, material}
* The sphere fields are: Sphere{radius, position, emission, color, material}
******************************************************************************/
const (
cen = Vec{50, 40.8, -860} // used by scene 1
Expand Down Expand Up @@ -361,7 +361,7 @@ fn rand_f64() f64 {
}

const (
cache_len = 65536 // the 2*pi angle will be splitted in 65536 part
cache_len = 65536 // the 2*pi angle will be split in 2^16 parts
cache_mask = cache_len - 1 // mask to speed-up the module process
)

Expand Down
8 changes: 4 additions & 4 deletions examples/pendulum-simulation/modules/sim/img/writer.v
Expand Up @@ -9,27 +9,27 @@ pub mut:
valid bool
}

pub struct ImageWritter {
pub struct ImageWriter {
settings ImageSettings
pub mut:
writer PPMWriter
current_index int
buffer []ValidColor
}

pub fn new_image_writer(mut writer PPMWriter, settings ImageSettings) &ImageWritter {
pub fn new_image_writer(mut writer PPMWriter, settings ImageSettings) &ImageWriter {
total_pixels := settings.width * settings.height
mut buffer := []ValidColor{len: total_pixels, init: ValidColor{
valid: false
}}
return &ImageWritter{
return &ImageWriter{
writer: writer
settings: settings
buffer: buffer
}
}

pub fn (mut iw ImageWritter) handle(result sim.SimResult) !int {
pub fn (mut iw ImageWriter) handle(result sim.SimResult) !int {
total_pixels := iw.settings.width * iw.settings.height

// find the closest magnet
Expand Down
2 changes: 1 addition & 1 deletion examples/pendulum-simulation/modules/sim/sim.v
Expand Up @@ -21,7 +21,7 @@ pub fn (mut state SimState) satisfy_rope_constraint(params SimParams) {

pub fn (mut state SimState) increment(delta_t f64, params SimParams) {
// 1. add up all forces
// 2. get an accelleration
// 2. get an acceleration
// 3. add to velocity
// 4. ensure rope constraint is satisfied

Expand Down
2 changes: 1 addition & 1 deletion examples/pendulum-simulation/modules/sim/vec.v
Expand Up @@ -9,7 +9,7 @@ pub struct Vector3D {
z f64
}

// vector creates a Vector3D passing x,y,z as parameteres
// vector creates a Vector3D passing x,y,z as parameters
pub fn vector(data Vector3D) Vector3D {
return Vector3D{
...data
Expand Down
4 changes: 2 additions & 2 deletions examples/regex/pcre.vv
Expand Up @@ -6,7 +6,7 @@ import pcre

fn example() {
r := pcre.new_regex('Match everything after this: (.+)', 0) or {
println('An error occured!')
println('An error occurred!')
return
}

Expand Down Expand Up @@ -49,7 +49,7 @@ fn main() {
regex := r'(\[[a-z\.\! ]*\]\( *\w*\:*\w* *\))*'

r := pcre.new_regex(regex, 0) or {
println('An error occured!')
println('An error occurred!')
return
}

Expand Down
4 changes: 2 additions & 2 deletions examples/sokol/01_cubes/cube.v
Expand Up @@ -8,7 +8,7 @@
*
* TODO:
* - add instancing
* - add an exampel with shaders
* - add an example with shaders
**********************************************************************/
import gg
import gx
Expand Down Expand Up @@ -53,7 +53,7 @@ fn create_texture(w int, h int, buf &u8) gfx.Image {
label: &u8(0)
d3d11_texture: 0
}
// commen if .dynamic is enabled
// comment, if .dynamic is enabled
img_desc.data.subimage[0][0] = gfx.Range{
ptr: buf
size: usize(sz)
Expand Down
2 changes: 1 addition & 1 deletion examples/sokol/02_cubes_glsl/cube_glsl.v
Expand Up @@ -394,7 +394,7 @@ fn draw_cube_glsl(app App) {
tr_matrix := m4.calc_tr_matrices(dw, dh, rot[0], rot[1], 2.0)
gfx.apply_viewport(ws.width / 2, 0, ws.width / 2, ws.height / 2, true)

// apply the pipline and bindings
// apply the pipeline and bindings
gfx.apply_pipeline(app.cube_pip_glsl)
gfx.apply_bindings(app.cube_bind)

Expand Down

0 comments on commit 993546a

Please sign in to comment.