~ubuntu-branches/ubuntu/breezy/lurker/breezy

« back to all changes in this revision

Viewing changes to libesort/File.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Meurer
  • Date: 2004-09-26 16:27:51 UTC
  • Revision ID: james.westby@ubuntu.com-20040926162751-z1ohcjltv7ojtg6z
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  $Id: File.h,v 1.3 2003/04/24 23:52:36 terpstra Exp $
 
2
 *  
 
3
 *  Master.h - Disk segment for commit'd inserts
 
4
 *  
 
5
 *  Copyright (C) 2002 - Wesley W. Terpstra
 
6
 *  
 
7
 *  License: GPL
 
8
 *  
 
9
 *  Authors: 'Wesley W. Terpstra' <wesley@terpstra.ca>
 
10
 *  
 
11
 *    This program is free software; you can redistribute it and/or modify
 
12
 *    it under the terms of the GNU General Public License as published by
 
13
 *    the Free Software Foundation; version 2.1.
 
14
 *    
 
15
 *    This program is distributed in the hope that it will be useful,
 
16
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 *    GNU General Public License for more details.
 
19
 *    
 
20
 *    You should have received a copy of the GNU General Public License
 
21
 *    along with this program; if not, write to the Free Software
 
22
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
23
 */
 
24
 
 
25
#ifndef FILE_H
 
26
#define FILE_H
 
27
 
 
28
#include <cmath>
 
29
#include "esort.h"
 
30
 
 
31
namespace ESort
 
32
{
 
33
 
 
34
class Source;
 
35
class FileSource;
 
36
 
 
37
inline int categorize(long records)
 
38
{
 
39
        return static_cast<int>(floor(log(static_cast<double>(records+2))/log(2)));
 
40
}
 
41
 
 
42
 
 
43
class File
 
44
{
 
45
 protected:
 
46
        int fd;
 
47
        const Parameters* p;
 
48
        long where;
 
49
        
 
50
 public:
 
51
        /** Use this file descriptor for operation
 
52
         */
 
53
        File(const string& id = "", int fd_ = -1, const Parameters* p_ = 0);
 
54
        File(const File& o); 
 
55
        ~File(); // closes fd
 
56
        
 
57
        /** The id of the database.
 
58
         */
 
59
        string id;
 
60
        
 
61
        /** The number of blocks in this file
 
62
         */
 
63
        long blocks;
 
64
        
 
65
        /** The classification based on size for this file
 
66
         */
 
67
        int category;
 
68
        
 
69
        /** Always succeeds */
 
70
        auto_ptr<Source> openBlock(long block, bool forward);
 
71
 
 
72
 friend class FileSource;
 
73
};
 
74
 
 
75
}
 
76
 
 
77
#endif