15-440 Project 2 FAQ

The following web page is supplement to the main project document, available as a PDF .

How do I turn in the project?

We will use Autolab, but the specific scripts we will want you to run to create your submission do not yet exist. Hang on for a bit, but later:

Should I write the tribbles to disk?

No. The back-end store is simply an in-memory hashtable (a Go map).

If I implement AddToList and RemoveFromList, why do I need Get and Put?

Remember, it is not a good design to store a user's tribbles in a list. Instead, the list should contain only tribble ids (that you have to define). Tribbles should be stored as separate objects in the hashtable, with the tribble id as the key. Get and Put should therefore be used for tribbles, and AddToList and RemoveFromList for manipulating lists (i.e., lists of tribble ids, and lists of "followees"). Also, we think you'll find the atomicity provided by the List functions quite useful.

Does GetTribblesBySubscription retrieve 100 tribbles for each followed user, or 100 tribbles in total?

100 in total.

Can I delete tribbles that are older than the most recent 100?

No. The back-end must store all tribbles ever posted.

Should both the keys and the values be JSON-encoded?

It is sufficient to encode only the values (before adding them to the hashtable).

How will points be allocated for the project?

Coming soon

How should my partner and I work on the project together?

We strongly recommend that you use git to do so. See the 15-410 Git Quickstart for help. More information coming on this soon.

How do I JSON-encode something in Go?

As you did in Project 1, use the package json. Documentation on specific usage is available at: http://golang.org/pkg/json/ and more information on JSON in general is available at http://www.json.org/.

What are some ways to serialize access to a map object?

As the saying goes, there is more than one way to skin this cat.

How do I create a map in Go?

The map data structure in Go allows you to associate values of any type (that are able to be compared with the == operator), with any other type.
Initialize a map as a type with:

type SomeMap map[int]string
myMap := make(SomeMap)
Add a value to the map with:
myMap[1] = "Some String"
You can retrieve this value, along with a boolean telling you if the key is present in the map, with:
value, present := myMap[1]
Remember, maps can store any type as the value, not just strings.

How do I serialize aceess to a map with a mutex lock in Go?

Utilize the "sync" package to apply a mutex lock to the data structure.
One way this can be implemented is to declare the map type as a struct with two fields - one for the map itself, and one for the lock.

import "sync"

type SomeMap struct {
     theData map[int]string
     theLock sync.Mutex
}
You then might add a convenience function to initialize your SomeMap struct, such as:
func NewSomeMap() *SomeMap {
     return &SomeMap {
     	    theData: make(map[int]string)
     }
}
(noting that the default for a lock is to have it be initialized, but unlocked)

Last updated: Tue Oct 09 21:47:20 -0400 2012 [validate xhtml]