Drizzled Public API Documentation

key_map.cc

00001 /* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #include <config.h>
00021 
00022 #include <drizzled/key_map.h>
00023 
00024 namespace drizzled
00025 {
00026 
00027 bool is_keymap_prefix(const key_map& map, const uint32_t prefix_size)
00028 {
00029   size_t pos= 0;
00030 
00031   for (; pos < prefix_size; pos++)
00032     if (! map.test(pos))
00033       return false;
00034 
00035   /*TODO: huh?
00036     uint32_t prefix_bits= prefix_size & 0x7;
00037     if (prefix_bits &&  != (1 << prefix_bits)-1)
00038     return false;
00039   */
00040 
00041   for (; pos < map.size(); pos++)
00042     if (map.test(pos))
00043       return false;
00044 
00045   return true;
00046 }
00047 
00048 void set_prefix(key_map& map, const uint32_t prefix_size)
00049 {
00050   size_t pos= 0;
00051 
00052   for (; pos < prefix_size && pos < map.size(); pos++)
00053   {
00054     map.set(pos);
00055   }
00056 }
00057 
00058 bool is_overlapping(const key_map& map, const key_map& map2)
00059 {
00060   size_t count;
00061   for (count= 0; count < map.size(); count++)
00062   {
00063     if (map[count] & map2[count])
00064       return false;
00065   }
00066   return true;
00067 }
00068 
00069 void key_map_subtract(key_map& map1, key_map& map2)
00070 {
00071   map1&= map2.flip();
00072   map2.flip();
00073 }
00074 
00075 } /* namespace drizzled */