Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better data structure for vendorMacs.json #8

Closed
brannondorsey opened this issue Mar 24, 2015 · 2 comments
Closed

Better data structure for vendorMacs.json #8

brannondorsey opened this issue Mar 24, 2015 · 2 comments

Comments

@brannondorsey
Copy link
Owner

A few quick thoughts about how we are storing, loading, parsing, and using this small database.

  1. We should load this file via AJAX instead of a script include to keep from stalling page load.
  2. We should store this as valid JSON rather than JS (creating and assigning a vendor object).
  3. We should use a dictionary-style data structure rather than an array so that lookups are less time consuming:
{
"00:00:00": "Xerox",
"00:00:01": "Xerox",
"00:00:02": "Xerox",
"00:00:03": "Xerox",
"00:00:04": "Xerox",
"00:00:05": "Xerox"
}

vs

"mapping": [
{
"mac_prefix": "00:00:00",
"vendor_name": "Xerox"
},
{
"mac_prefix": "00:00:01",
"vendor_name": "Xerox"
},
{
"mac_prefix": "00:00:02",
"vendor_name": "Xerox"
},
{
"mac_prefix": "00:00:03",
"vendor_name": "Xerox"
},
{
"mac_prefix": "00:00:04",
"vendor_name": "Xerox"
},
{
"mac_prefix": "00:00:05",
"vendor_name": "Xerox"
}
]

Then lookups are as easy as:

if (vendors.hasOwnProperty("00:00:00")) {
    var ven = vendors["00:00:00"]
}

rather than

for (var i = 0; i < vendor.mapping.length; i++) {
     if (vendor.mapping[i].mac_prefix == "00:00:00"){
        var ven =   vendor.mapping[i].vendor_name;          
     }
}

This isn't urgent and changes will overhaul some working code, so lets do this another day. I am up to make this change if you agree that this is the right decision @nbriz.

@nbriz
Copy link
Collaborator

nbriz commented Mar 24, 2015

yea, that was a lazy implementation on my part ^___^

brannondorsey added a commit that referenced this issue Mar 28, 2015
@brannondorsey
Copy link
Owner Author

Vendor data is now being stored in a hashmap format and loaded via AJAX rather than a <script> include tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants