<commit_before>/***************************************************************************************************
 *  MultiMap.swift
 *
 *  This file defines a multi-key map data structure.
 *
 *  Author: <NAME>
 *  Creation Date: 21 Dec 2016
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the 
 *  License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 
 *  express or implied. See the License for the specific language governing permissions and 
 *  limitations under the License.
 *
 *  Copyright 2016 <NAME>
 **************************************************************************************************/

// Adapted from the section on "Ternary Search Tries" in "Algorithms, 4th Edition", Sedgewick, 
// R., <NAME>. (2011). 

// TODO: make dictionary iterable!

// TODO: allow for wild card inserts: this allows nil values in the insertion keyset. The result of 
//	this operation is to 1) re-write the values for any existing keys that match the given key set and
//	2) insert a new node such that any specific query on the wildcard will match. 
//
// Maybe the 2 features noted above should be separate functions? insert and upate?
// 
// For example, dictionary D has entries: ["Bob", "Smith", "Blonde"]=4 and ["Bob", "Ross", "Blonde"]=27.
// Now, D.insert(9, keys: "Bob", nil, "Blonde") should result in having ["Bob","Smith","Blonde"]=9 and 
// ["Bob","Ross","Blonde"]=9 and ["Bob", nil, "Blonde"]=9. If I were later to do D.find("Bob","Jensen","Blonde"),
// it would match the wildcard middle key and return 9.

// TODO: add method that performs a wildcard find, but returns all found values AND their entire key set
// For example, for D.find(["Bob", nil, "Blond"]), I might want to get back (["Bob", "Smith", "Blond"], 4)
// and (["Bob", "Ross", "Blond"], 27)

public struct MultiMap<Key: Comparable, Value>
{   
    public var count: Int 
    public let keyCount: Int     

    /// Initialize a new multikey dictionary where elements are indexed by the given number of keys.
    ///
    /// - Parameters:
    ///		- keys: number of keys to index each element with
    public init(keys: Int)
    {
        self.count = 0
        self.keyCount = keys
        self.root = nil      
    }

    /// Insert a new value into the dictionary with the given keys.
    ///
    /// - Parameters:<commit_msg>Add todo to document multimap better<commit_after>/***************************************************************************************************
 *  MultiMap.swift
 *
 *  This file defines a multi-key map data structure.
 *
 *  Author: <NAME>
 *  Creation Date: 21 Dec 2016
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the 
 *  License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 
 *  express or implied. See the License for the specific language governing permissions and 
 *  limitations under the License.
 *
 *  Copyright 2016 <NAME>
 **************************************************************************************************/

// Adapted from the section on "Ternary Search Tries" in "Algorithms, 4th Edition", Sedgewick, 
// R., Wayne, K. (2011). 

// TODO: make dictionary iterable!

// TODO: allow for wild card inserts: this allows nil values in the insertion keyset. The result of 
//	this operation is to 1) re-write the values for any existing keys that match the given key set and
//	2) insert a new node such that any specific query on the wildcard will match. 
//
// Maybe the 2 features noted above should be separate functions? insert and upate?
// 
// For example, dictionary D has entries: ["Bob", "Smith", "Blonde"]=4 and ["Bob", "Ross", "Blonde"]=27.
// Now, D.insert(9, keys: "Bob", nil, "Blonde") should result in having ["Bob","Smith","Blonde"]=9 and 
// ["Bob","Ross","Blonde"]=9 and ["Bob", nil, "Blonde"]=9. If I were later to do D.find("Bob","Jensen","Blonde"),
// it would match the wildcard middle key and return 9.

// TODO: add method that performs a wildcard find, but returns all found values AND their entire key set
// For example, for D.find(["Bob", nil, "Blond"]), I might want to get back (["Bob", "Smith", "Blond"], 4)
// and (["Bob", "Ross", "Blond"], 27)

// TODO: add better documentation for this class. Explaining what it does, giving some motivation, and showing example usage.
public struct MultiMap<Key: Comparable, Value>
{   
    public var count: Int 
    public let keyCount: Int     

    /// Initialize a new multikey dictionary where elements are indexed by the given number of keys.
    ///
    /// - Parameters:
    ///		- keys: number of keys to index each element with
    public init(keys: Int)
    {
        self.count = 0
        self.keyCount = keys
        self.root = nil      
    }

    /// Insert a new value into the dictionary with the given keys.
    ///
    /// - Parameters:
{'fraction_non_alphanumeric': 0.1784331797235023, 'fraction_numerical': 0.012534562211981567, 'mean_word_length': 3.368760064412238, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '622279', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1431, 'n_words': 677}