

class ColumnFamily(object):
    """Column Family objects store information about all rows.

    daily_purchases_cf = ColumnFamily("daily_purchases")
    """

    def __init__(self, name, data_dir='data'):
        self.name = name
        self.ROWS = set()

    def insert(self, column):
        return self._insert(column)

    def delete(self, column):
        column.tombstone = True
        return self._insert(column)

    def get(self, key):
        # NOTE: Check for tombstones / TTL here
        pass

    def _insert(self, column):
        try:
            self.ROWS.add(column)
            return True
        except:
            return False

    def __repr__(self):
        return '<%r>' % self.name



class ColumnFamily(object):
    """Column Family objects store information about all rows.

    daily_purchases_cf = ColumnFamily("daily_purchases")
    """

    def __init__(self, name, data_dir='data'):
        self.name = name
        # A row consists of:
        # {'rowkey': [col1, col2, col3]}
        self.ROWS = dict()

    def insert(self, column):
        return self._insert(column)

    def delete(self, column):
        column.tombstone = True
        return self._insert(column)

    def get(self, key):
        # NOTE: Check for tombstones / TTL here
        pass

    def _insert(self, column):
        try:
            self.ROWS[column.row_key].append(column)
            return True
        except KeyError: # Key doesn't exist
            self.ROWS[column.row_key] = [column]
        except:
            return False

    def __repr__(self):
        return '<%r>' % self.name

Store rows as dictionaries of lists.
Store rows as dictionaries of lists.

  
  
  class ColumnFamily(object):
      """Column Family objects store information about all rows.
  
      daily_purchases_cf = ColumnFamily("daily_purchases")
      """
  
      def __init__(self, name, data_dir='data'):
          self.name = name
+         # A row consists of:
+         # {'rowkey': [col1, col2, col3]}
-         self.ROWS = set()
+         self.ROWS = dict()
  
      def insert(self, column):
          return self._insert(column)
  
      def delete(self, column):
          column.tombstone = True
          return self._insert(column)
  
      def get(self, key):
          # NOTE: Check for tombstones / TTL here
          pass
  
      def _insert(self, column):
          try:
-             self.ROWS.add(column)
+             self.ROWS[column.row_key].append(column)
              return True
+         except KeyError: # Key doesn't exist
+             self.ROWS[column.row_key] = [column]
          except:
              return False
  
      def __repr__(self):
          return '<%r>' % self.name
  
Store rows as dictionaries of lists.
## Code Before:


class ColumnFamily(object):
    """Column Family objects store information about all rows.

    daily_purchases_cf = ColumnFamily("daily_purchases")
    """

    def __init__(self, name, data_dir='data'):
        self.name = name
        self.ROWS = set()

    def insert(self, column):
        return self._insert(column)

    def delete(self, column):
        column.tombstone = True
        return self._insert(column)

    def get(self, key):
        # NOTE: Check for tombstones / TTL here
        pass

    def _insert(self, column):
        try:
            self.ROWS.add(column)
            return True
        except:
            return False

    def __repr__(self):
        return '<%r>' % self.name

## Instruction:
Store rows as dictionaries of lists.
## Code After:


class ColumnFamily(object):
    """Column Family objects store information about all rows.

    daily_purchases_cf = ColumnFamily("daily_purchases")
    """

    def __init__(self, name, data_dir='data'):
        self.name = name
        # A row consists of:
        # {'rowkey': [col1, col2, col3]}
        self.ROWS = dict()

    def insert(self, column):
        return self._insert(column)

    def delete(self, column):
        column.tombstone = True
        return self._insert(column)

    def get(self, key):
        # NOTE: Check for tombstones / TTL here
        pass

    def _insert(self, column):
        try:
            self.ROWS[column.row_key].append(column)
            return True
        except KeyError: # Key doesn't exist
            self.ROWS[column.row_key] = [column]
        except:
            return False

    def __repr__(self):
        return '<%r>' % self.name
