Return to Video

Lookup Solution - Web Development

  • 0:00 - 0:03
    Here's my solution to this quiz.
  • 0:03 - 0:06
    We first add this link
  • 0:06 - 0:09
    that was passed in as a parameter to our links list.
  • 0:09 - 0:13
    And then we add it to our index by saying link.id=link
  • 0:13 - 0:15
    into the global index here.
  • 0:15 - 0:17
    And let's go ahead and give this function a test.
  • 0:17 - 0:20
    The first thing we need to do is create a link, so I'll do that now.
  • 0:20 - 0:24
    So we create a new link, and it's going to have id 50.
  • 0:24 - 0:28
    And then we needed a user id, a submission time, and number of votes,
  • 0:28 - 0:31
    which we'll just set to 1 for now.
  • 0:31 - 0:34
    It needs a title and a URL.
  • 0:34 - 0:36
    So that should make a link.
  • 0:36 - 0:39
    And now let's actually call our function add new link L.
  • 0:39 - 0:42
    And now, let's make sure it works.
  • 0:42 - 0:45
    So the first thing I want to do is make sure we added it to the list link.
  • 0:45 - 0:48
    So we're going to say print links negative 1,
  • 0:48 - 0:51
    Which will print the last element in our list of links.
  • 0:51 - 0:54
    And that's where this link should be
  • 0:54 - 0:56
    because we appended it to that list.
  • 0:56 - 1:03
    I'm also going to print link by id 50.
  • 1:03 - 1:05
    So these should actually print the same thing
  • 1:05 - 1:07
    and they should both be our new list--or our new link.
  • 1:07 - 1:08
    Let's go ahead and give that a shot.
  • 1:08 - 1:11
    Ta-da! All right, so we've updated our list,
  • 1:11 - 1:14
    and we've updated our index--pretty cool.
  • 1:14 - 1:18
    So as you can see, an index is really handy
  • 1:18 - 1:22
    making reads simpler so you don't have to iterate over the entire list,
  • 1:22 - 1:24
    but there's a certain maintenance cost to having them
  • 1:24 - 1:28
    in that you have to keep it up to date when you're updating the rest of your database.
  • 1:28 - 1:31
    And you can imagine if you had multiple indexes on your table,
  • 1:31 - 1:33
    which you can,
  • 1:33 - 1:35
    every time you insert a new element into your table,
  • 1:35 - 1:37
    you need to update all of these indexes.
  • 1:37 - 1:41
    Okay, great. Let's move on to another quiz.
Title:
Lookup Solution - Web Development
Description:

more » « less
Video Language:
English
Team:
Udacity
Project:
CS253 - Web Development
Duration:
01:40

English subtitles

Revisions Compare revisions