-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.cpp
More file actions
46 lines (41 loc) · 1.27 KB
/
Node.cpp
File metadata and controls
46 lines (41 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// Node.cpp
// Project 4
//
// Created by Nihar Tamhankar on 5/30/16.
// Copyright © 2016 Nihar Tamhankar. All rights reserved.
//
#include "Node.h"
#include <iostream>
using namespace std;
Node::Node(){
next=nullptr;
}
NodeHashTable::NodeHashTable(int size):m_size(size), hashtable(size, nullptr){ //makes a hashtable of with size buckets all point to nullpointer
}
void NodeHashTable::insertNode(Node* node){
hash<string> hasfunc; //using C++ hash function for string
int index =(hasfunc(node->token)% m_size); //hashing based on value
Node* current= hashtable[index];
if(current==nullptr){
hashtable[index]=node; //if hash value points to null, entering first value
return;
}
while(current->next!=nullptr){
current=current->next; //adding to linked list
}
current->next=node;
node->next=nullptr;
}
Node* NodeHashTable::find( string pattern){ ///using C++ hash string function to see if value is in hash table
hash<string>hasfunc;
int index=(hasfunc(pattern)%m_size);
Node* current= hashtable[index];
while(current!=nullptr){
if(current->token==pattern){
return current;
}
current=current->next;
}
return nullptr;///if not found return null
}