List:Internals« Previous MessageNext Message »
From:Mats Kindahl Date:March 16 2005 1:55pm
Subject:bk commit into 5.1 tree (mats:1.1790)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of mats. When mats does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1790 05/03/16 14:55:28 mats@stripped +3 -0
  WL#2324: Injector support in MySQL 
  Adding bitvector to give columns that are present in the record.
  Added new bitvector class to handle the bitvector.

  sql/bitvector.h
    1.1 05/03/16 14:55:14 mats@stripped +165 -0

  sql/injector.h
    1.2 05/03/16 14:55:14 mats@stripped +8 -6
    Adding bitvector to give columns that are present in the record.

  sql/injector.cc
    1.2 05/03/16 14:55:14 mats@stripped +6 -2
    Adding bitvector to give columns that are present in the record.

  sql/bitvector.h
    1.0 05/03/16 14:55:14 mats@stripped +0 -0
    BitKeeper file /home/bk/w2324-mysql-5.1/sql/bitvector.h

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	mats
# Host:	romeo.kindahl.net
# Root:	/home/bk/w2324-mysql-5.1
--- New file ---
+++ sql/bitvector.h	05/03/16 14:55:14
/* Copyright (C) 2005 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#ifndef BITVECTOR_H
#define BITVECTOR_H

#include "my_global.h"		// Pull in 'byte', 'my_off_t', and 'uint32'
#include <string.h>

namespace {
    template <class T> 
    inline void my_swap(T& x, T& y) { 
	T t(x); x = y; y = t; 
    }
}

/*
  A dynamic bitvector for storing bits.

  Right now, the vector cannot change size. It's only used as a replacement
  for using an array of bytes and a counter.
*/
class bitvector {
private:
  // Helper classes
  struct flip_bit { 
    void operator()(unsigned char* p, unsigned char m) { *p ^= m; }
  };

  struct set_bit { 
    void operator()(unsigned char* p, unsigned char m) { *p |= m; }
  };

  struct clear_bit { 
    void operator()(unsigned char* p, unsigned char m) { *p &= ~m; }
  };

  struct test_bit { 
    bool operator()(unsigned char* p, unsigned char m) { return *p & m; }
  };

  static inline size_t byte_size(size_t bits) { 
    return (bits + 7) / 8; 
  }

  template <class ReturnType, class Func>
  inline ReturnType apply_to_byte(size_t const pos, Func op) const
  {
    ptrdiff_t const byte_pos = pos >> 3;
    unsigned char const mask = (1 << (pos & 0x7U));
    return op(&m_data[byte_pos], mask);
  }

public:
  explicit bitvector(size_t size, bool value = false) 
    : m_size(size), m_data(new unsigned char[byte_size(size)])
  {
    if (value)
      set();
    else
      reset();
  }

  // Constructor to create a bitvector from data. Observe that 'size' is the
  // number of *bits* in the bitvector. 
  explicit bitvector(unsigned char const* data, size_t size)
    : m_size(size), m_data(new unsigned char[byte_size(size)])
  {
    memcpy(m_data, data, byte_size(size));
  }

  bitvector(bitvector const& other) 
    : m_size(other.size()), m_data(new unsigned char[other.bytes()])
  {
    // std::copy(other.m_data, other.m_data + other.bytes(), m_data);
    memcpy(m_data, other.data(), other.bytes());
  }

  bitvector& operator=(bitvector other) {
    swap(other);
    return *this;
  }

  ~bitvector() 
  {
    delete[] m_data;
  }

  // Swap the guts of this instance with another instance.
  void swap(bitvector& other) {
    my_swap(m_size, other.m_size);
    my_swap(m_data, other.m_data);
  }

  // A pointer to the bytes representing the bits
  unsigned char const *data() const { return m_data; }

  // The size of the data in *bytes*
  size_t bytes() const { return byte_size(m_size); }

  // The number of bits in the bit vector
  size_t size() const { return m_size; }

  // Set all bits in the vector
  bitvector& set() { 
    // I would really like to use std::fill() here, but I'm not sure it's
    // allowed.
    // std::fill(m_data, m_data + bytes(), 255);
    memset(m_data, 255, bytes()); 
    return *this;
  }

  // Set a bit to a value
  bitvector& set(size_t pos, int val = true) {
    if (val)
      apply_to_byte<void>(pos, set_bit());
    else
      apply_to_byte<void>(pos, clear_bit());
    return *this;
  }

  // Reset (clear) all bits in the vector
  bitvector& reset() { 
    // std::fill(m_data, m_data + bytes(), 255);
    memset(m_data, 0, bytes()); 
    return *this;
  }

  // Reset one bit in the vector
  bitvector& reset(size_t pos) {
    apply_to_byte<void>(pos, clear_bit());
    return *this;
  }

  bitvector& flip(size_t pos) {
    apply_to_byte<void>(pos, flip_bit());
    return *this;
  }

  // Argh! There's a macro named 'test'.
  bool (test)(size_t pos) const {
    return apply_to_byte<bool>(pos, test_bit());
  };

private:
  size_t m_size;
  unsigned char *m_data;
};


#endif // BITVECTOR_H



--- 1.1/sql/injector.cc	2005-02-25 12:31:38 +01:00
+++ 1.2/sql/injector.cc	2005-03-16 14:55:14 +01:00
@@ -23,6 +23,7 @@
 
 int injector::transaction::
 write_row (server_id_type sid, table tbl, 
+	   bitvector const& cols, 
 	   record_type record)
 {
    DBUG_ENTER("injector::transaction::write_row(...)");
@@ -32,6 +33,7 @@
 
 int injector::transaction::
 delete_row(server_id_type sid, table tbl,
+	   bitvector const& cols, 
 	   record_type record)
 {
    DBUG_ENTER("injector::transaction::delete_row(...)");
@@ -41,7 +43,8 @@
 
 int injector::transaction::
 update_row(server_id_type sid, table tbl, 
-	   record_type before, record_type after)
+	   bitvector const& before_cols, record_type before, 
+	   bitvector const& after_cols, record_type after)
 {
    DBUG_ENTER("injector::transaction::update_row(...)");
    DBUG_RETURN(0);
@@ -69,7 +72,8 @@
 injector* injector::
 instance()
 {
-  return new injector();
+  static injector s_injector;
+  return &s_injector;		// There is only one instance
 }
 
 

--- 1.1/sql/injector.h	2005-02-25 12:31:37 +01:00
+++ 1.2/sql/injector.h	2005-03-16 14:55:14 +01:00
@@ -21,6 +21,7 @@
 #define INJECTOR_H
 
 #include "my_global.h"		// Pull in 'byte', 'my_off_t', and 'uint32'
+#include "bitvector.h"
 
 // Forward declarations
 class handler;
@@ -70,7 +71,7 @@
       class table {
       public:
 	table(char const* name) : m_name(name) { }
-	table(const table& t) : m_name(t.m_name) { }
+	table(table const& t) : m_name(t.m_name) { }
       private:
 	char const* m_name;
       };
@@ -95,19 +96,20 @@
 	Add a 'write row' entry to the transaction.
       */
       int write_row (server_id_type sid, table tbl, 
-		     record_type record);
+		     bitvector const& cols, record_type record);
 
       /*
 	Add a 'delete row' entry to the transaction.
       */
-      int delete_row(server_id_type sid, table tbl,
-		     record_type record);
+      int delete_row(server_id_type sid, table tbl, 
+		     bitvector const& cols, record_type record);
 
       /*
 	Add an 'update row' entry to the transaction.
       */
-      int update_row(server_id_type sid, table tbl,
-		     record_type before, record_type after);
+      int update_row(server_id_type sid, table tbl, 
+		     bitvector const& before_cols, record_type before, 
+		     bitvector const& after_cols,  record_type after);
 
       /*
 	Commit a transaction.
Thread
bk commit into 5.1 tree (mats:1.1790)Mats Kindahl16 Mar