Coder Social home page Coder Social logo

cs4500-assignment-1-part-2's Introduction

cs4500-assignment-1-part-2

By Kaylin Devchand & Cristian Stransky

Outline:
    Object:
        size_t hash()
        bool equals(Object* other)
        void print()

    String : Object:
        String* concat(String s)
        void concat_char(char c)
        size_t length()

    Map : Object:
        size_t size()

        MapStrObj : Map:
            void put(String* key, Object* val)
            Object* get(String* key)
            Object* remove(String* key)
            bool contains_key(String* key)
            String** get_keys()
            String** get_values()

        MapStrStr : Map:
            void put(String* key, String* val)
            String* get(String* key)
            String* remove(String* key)
            bool contains_key(String* key)
            String** get_keys()
            String** get_values()  

Object

Each and every object will have a hash code of some kind to allow for all objects to be manipulated
in a similiar fashion (sorting different objects for example). This hash value will also allow us to
use the equals function to see if two objects are equivalent.

The print function is mainly used for debugging, as it is quite useful to have a console line
representation of an object.

String

The string class has been made to allow for easier use of character arrays in CwC.

We make use of two concatenate functions (concat, concat_char) that will mutate the string itself.
We decided mutating the string in the function let's the user worry less about memory
allocation/deallocation than if the concatenate functions were returning a new string without
mutating the string.

The functions get_char, set_char, and length are to be used for for loop manipulation. Being able to
manipulate separate characters may be helpful.

The function replace is mainly used for a more robust method of being able to manipulate strings,
instead of only using characters. Using the function replace multiple times can remove all spaces in
a string for example:

while(!has_no_spaces(string)) {  
    string->replace(" ", "")  
}  

Or it can be used if the user wishes to check for strings with relation to each other,
like: string->replace("\r\n", " ").

Map

A map needs its intended function of being able to store and retrieve data based off a unique key,
which is why we have the basic functions of put and get. This operation needs to be completed at a
time of O(1) by using the power of indexing on an array of "buckets".

It also may be useful to completely remove a pairing (and not just the value) from a map, so the
function remove will free up both the key and value, as not to interfere with the functions like
contains_key or get_keys.

Sometimes, it may be useful to iterate through a map like an unsorted array, which is why the
function get_keys can be used to iterate through the keys, which allows for the values to be
iterated through as well. We have also added the function get_values if the user wishes to abstract
this process.

Since our map uses indexing, it's important that we have a boolean function contains_key to make
sure we know the key exists first before trying to get a value from it. This is a valuable way to
avoid index out of bounds errors.

cs4500-assignment-1-part-2's People

Contributors

a-colabella avatar buntry avatar chasebroder avatar csstransky avatar kaylindevchand avatar mkierzenka avatar rohitppathak avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.