<commit_before>public class Node {
  var character: String?
  var parent: Node?
  var children: [String:Node]
  var isAWord: Bool

  init(c: String){
    self.character = c
    self.children = [String:Node]()
    self.isAWord = false
    }

  //Easier getter function, probably will make it more swift like
  func char() -> String {
    return self.character!
  }

  func changeChar(c: String) -> Void {
    self.character = c
  }

  //For Testing purposes
  func getParent() -> Node {
    return parent!
  }

  //Is this node marked as the end of a word?
  func isValidWord() -> Bool{
    return self.isAWord
  }

  //Setters
  func isWord() -> Void {
    self.isAWord = true
  }

  func isNotWord() -> Void {
    self.isAWord = false
  }

  func isRoot() -> Bool {
    return self.character == ""
  }
}

public class Trie {
  var root = Node(c: "")
  var nodes: [Node]

  init() {
    self.root = Node(c: "")
    self.nodes = []
    self.nodes.append(self.root)
  }

  func find(key: String) -> (key: String, found: Bool) {
    var currentNode = self.root

    for c in key.characters {
      if currentNode.children[String(c)] == nil {
        return(key, false)
      }
      currentNode = currentNode.children[String(c)]!
    }

    return(key, currentNode.isValidWord())
  }

  func insert(w: String) -> (word: String, inserted: Bool) {

    var currentNode = self.root
    var length = w.characters.count

    for c in w.characters {
      if currentNode.children[String(c)] != nil {
        currentNode = currentNode.children[String(c)]!
        length -= 1
      }
    }

    if length == 0 {
      if(currentNode.isValidWord()) {
        return (w, false)
      }

      currentNode.isWord()
      return (w, true)
    }

    let choppedWord = String(w.characters.suffix(length))

    print(choppedWord)
    for c in choppedWord.characters {
      currentNode.children[String(c)] = Node(c: String(c))
      currentNode = currentNode.children[String(c)]!
    }

    currentNode.isWord()
    return (w, true)
  }

}

print("tests")

/*var x: Node = Node(c: "c")
print(x.char())
print(x.isValidWord())
x.isWord()
print(x.isValidWord())*/


var T: Trie = Trie()
print(T.insert("Hello"))
print(T.find("Hello"))<commit_msg>got rid of debugging statements<commit_after>public class Node {
  var character: String?
  var parent: Node?
  var children: [String:Node]
  var isAWord: Bool

  init(c: String){
    self.character = c
    self.children = [String:Node]()
    self.isAWord = false
    }

  //Easier getter function, probably will make it more swift like
  func char() -> String {
    return self.character!
  }

  func changeChar(c: String) -> Void {
    self.character = c
  }

  //For Testing purposes
  func getParent() -> Node {
    return parent!
  }

  //Is this node marked as the end of a word?
  func isValidWord() -> Bool{
    return self.isAWord
  }

  //Setters
  func isWord() -> Void {
    self.isAWord = true
  }

  func isNotWord() -> Void {
    self.isAWord = false
  }

  func isRoot() -> Bool {
    return self.character == ""
  }
}

public class Trie {
  var root = Node(c: "")
  var nodes: [Node]
  var wordList: [String]
  var wordCount = 0

  init() {
    self.root = Node(c: "")
    self.nodes = []
    self.nodes.append(self.root)
  }

  func find(key: String) -> (key: String, found: Bool) {
    var currentNode = self.root

    for c in key.characters {
      if currentNode.children[String(c)] == nil {
        return(key, false)
      }
      currentNode = currentNode.children[String(c)]!
    }

    return(key, currentNode.isValidWord())
  }

  func insert(w: String) -> (word: String, inserted: Bool) {

    var currentNode = self.root
    var length = w.characters.count

    for c in w.characters {
      if currentNode.children[String(c)] != nil {
        currentNode = currentNode.children[String(c)]!
        length -= 1
      }
    }

    if length == 0 {
      if(currentNode.isValidWord()) {
        return (w, false)
      }

      currentNode.isWord()
      wordList.append(w)
      wordCount += 1
      return (w, true)
    }

    let choppedWord = String(w.characters.suffix(length))

    for c in choppedWord.characters {
      currentNode.children[String(c)] = Node(c: String(c))
      currentNode = currentNode.children[String(c)]!
    }

    currentNode.isWord()
    wordList.append(w)
    wordCount += 1
    return (w, true)
  }

  func remove(w: String) {


  }

}

print("tests")

/*var x: Node = Node(c: "c")
print(x.char())
print(x.isValidWord())
x.isWord()
print(x.isValidWord())*/


var T: Trie = Trie()
print(T.insert("Hello"))
print(T.find("Hello"))
{'fraction_non_alphanumeric': 0.14059792027729637, 'fraction_numerical': 0.0015164644714038128, 'mean_word_length': 2.5325172149961745, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '57138', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1555, 'n_words': 393}