Skip to content

Instantly share code, notes, and snippets.

@kaikuchn
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaikuchn/de57ad11f532b079dace to your computer and use it in GitHub Desktop.
Save kaikuchn/de57ad11f532b079dace to your computer and use it in GitHub Desktop.
Function find_or_create_node(dict As Dictionary, key As String) As Dictionary
If Not dict.Exists(key)
dict.Add(key, new Dictionary)
End If
Return dict.Item(key)
End Function
Sub initialize_or_increment_leaf(dict As Dictionary, key As String, value As Double)
If Not dict.Exists(key)
dict.Add(key, value)
Else
dict.Item(key) = dict.Item(key) + value
End If
End Sub
' Use like this
sub_projects_dict = find_or_create_node(projects_dict, project_id);
months_dict = find_or_create_node(sub_projects_dict, sub_project_id);
initialize_or_increment_leaf(months_dict, current_month, working_hours);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment