22-Section-Handout

22-Section-Handout - CS106X Autumn 2009 Handout 22 Section...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS106X Handout 22 Autumn 2009 October 26 th , 2009 Section Handout Problem 1: The Sparse String Vector A SparseStringVector is a Vector<string> -like data structure that provides super fast access to its elements, and near constant-time insertion and deletion. It layers array semantics over an ordered collection of C++ strings, with the understanding that most of the strings are empty . The SparseStringVector is different from our C++ Vector and other array-like data structures, because it’s stingy in its use of memory. Each empty string requires just one bit of storage, which is less than 3% of the memory cost incurred by the allocation of a full string . The implementation is slower than our Vector , but it’s a wise choice when memory is at a premium and an overwhelmingly large fraction of the strings being stored are empty. Our SparseStringVector is backed by an array of group s, where each group is responsible for managing a contiguous subset of array indices. The programmer specifies not only the logical length of the SparseStringVector , but also the group size. If the logical length of the full SparseStringVector is, for instance, established as 50,000, and the group size is established to be 100, then group 0 manages indices 0 through 99, group 1 manages indices 100 through 199, group 2 manages indices 200 through 299, and so forth. All search, insert, and delete operations are passed on to the appropriate group. Here’s a glimpse of our class’s private sector: private: group *groups; // dynamically allocated array of structs, defined below int numGroups; // number of groups int arrayLength; // logical length of the full SparseStringVector
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/07/2010 for the course CS 201 taught by Professor Selimaksoy during the Spring '09 term at Bilkent University.

Page1 / 4

22-Section-Handout - CS106X Autumn 2009 Handout 22 Section...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online