Commit 09775ba4 authored by Scott Wheeler's avatar Scott Wheeler

Updated the version number to 0.9. Made SortedString list a BST and

StringHash a hash tree.

svn path=/trunk/kdemultimedia/juk/; revision=204462
parent 39af0c0b
......@@ -3,12 +3,12 @@ bin_PROGRAMS = juk
## INCLUDES were found outside kdevelop specific part
juk_SOURCES = sortedstringlist.cpp systemtray.cpp genrelisteditor.cpp genrelisteditorbase.ui splashscreen.cpp statuslabel.cpp cachedtag.cpp oggtag.cpp id3tag.cpp collectionlist.cpp playlistitem.cpp playlist.cpp playlistsplitter.cpp listboxpixmap.cpp playlistbox.cpp tageditor.cpp cache.cpp audiodata.cpp genrelistreader.cpp genrelistlist.cpp genrelist.cpp genre.cpp player.cpp tag.cpp customaction.cpp slideraction.cpp juk.cpp main.cpp
juk_SOURCES = stringhash.cpp sortedstringlist.cpp systemtray.cpp genrelisteditor.cpp genrelisteditorbase.ui splashscreen.cpp statuslabel.cpp cachedtag.cpp oggtag.cpp id3tag.cpp collectionlist.cpp playlistitem.cpp playlist.cpp playlistsplitter.cpp listboxpixmap.cpp playlistbox.cpp tageditor.cpp cache.cpp audiodata.cpp genrelistreader.cpp genrelistlist.cpp genrelist.cpp genre.cpp player.cpp tag.cpp customaction.cpp slideraction.cpp juk.cpp main.cpp
juk_LDADD = -lid3 -lsoundserver_idl $(LIB_KFILE) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT) $(LIBSOCKET)
SUBDIRS = pics data
EXTRA_DIST = main.cpp juk.cpp juk.h juk.desktop jukui.rc slideraction.cpp slideraction.h customaction.h customaction.cpp tag.cpp tag.h player.cpp player.h genre.h genre.cpp hi16-app-juk.png hi32-app-juk.png hi48-app-juk.png genrelist.cpp genrelist.h genrelistlist.cpp genrelistlist.h genrelistreader.cpp genrelistreader.h audiodata.cpp audiodata.h cache.cpp cache.h tageditor.cpp tageditor.h playlistbox.cpp playlistbox.h listboxpixmap.cpp listboxpixmap.h playlistsplitter.cpp playlistsplitter.h playlist.cpp playlist.h playlistitem.cpp playlistitem.h collectionlist.cpp collectionlist.h id3tag.cpp id3tag.h oggtag.cpp oggtag.h cachedtag.cpp cachedtag.h statuslabel.cpp statuslabel.h splashscreen.cpp splashscreen.h genrelisteditorbase.ui genrelisteditor.cpp genrelisteditor.h systemtray.h systemtray.cpp sortedstringlist.cpp sortedstringlist.h
EXTRA_DIST = main.cpp juk.cpp juk.h juk.desktop jukui.rc slideraction.cpp slideraction.h customaction.h customaction.cpp tag.cpp tag.h player.cpp player.h genre.h genre.cpp hi16-app-juk.png hi32-app-juk.png hi48-app-juk.png genrelist.cpp genrelist.h genrelistlist.cpp genrelistlist.h genrelistreader.cpp genrelistreader.h audiodata.cpp audiodata.h cache.cpp cache.h tageditor.cpp tageditor.h playlistbox.cpp playlistbox.h listboxpixmap.cpp listboxpixmap.h playlistsplitter.cpp playlistsplitter.h playlist.cpp playlist.h playlistitem.cpp playlistitem.h collectionlist.cpp collectionlist.h id3tag.cpp id3tag.h oggtag.cpp oggtag.h cachedtag.cpp cachedtag.h statuslabel.cpp statuslabel.h splashscreen.cpp splashscreen.h genrelisteditorbase.ui genrelisteditor.cpp genrelisteditor.h systemtray.h systemtray.cpp sortedstringlist.cpp sortedstringlist.h stringhash.cpp stringhash.h
install-data-local:
$(mkinstalldirs) $(kde_appsdir)/Multimedia/
......
......@@ -29,7 +29,7 @@
#include "collectionlist.h"
#include "tageditor.h"
#include "playlist.h"
#include "sortedstringlist.h"
#include "stringhash.h"
class PlaylistBoxItem;
......@@ -276,7 +276,7 @@ private:
CollectionList *collection;
SortedStringList playlistFiles;
StringHash playlistFiles;
QStringList mediaExtensions;
QStringList listExtensions;
......
......@@ -19,77 +19,56 @@
#include "sortedstringlist.h"
static const int tableSize = 5003;
class SortedStringList::Node
class SortedStringList::Node
{
public:
Node(const QString &value) : key(value), next(0) {}
~Node() {}
enum Color { Red, Black };
Node(const QString &value) : key(value), parent(0), left(0), right(0), color(Black) {}
~Node();
QString key;
Node *next;
Node *parent;
Node *left;
Node *right;
Color color;
};
SortedStringList::SortedStringList() : table(tableSize)
SortedStringList::SortedStringList() : root(0)
{
}
SortedStringList::~SortedStringList()
{
for(int i = 0; i < tableSize; i++)
deleteNode(table[i]);
}
bool SortedStringList::insert(const QString &value)
{
int h = hash(value);
Node *i = table[h];
Node *j = 0;
while(i) {
if(i->key == value)
return true;
else {
j = i;
i = i->next;
}
}
if(j)
j->next = new Node(value);
else
table.insert(h, new Node(value));
return false;
return BSTInsert(value);
}
bool SortedStringList::contains(const QString &value) const
{
int h = hash(value);
Node *i = table[h];
while(i && i->key != value)
i = i->next;
Node *n = root;
while(n && value != n->key) {
if(value < n->key)
n = n->left;
else
n = n->right;
}
return bool(i);
if(n)
return true;
else
return false;
}
QStringList SortedStringList::values() const
{
QStringList l;
Node *n;
for(int i = 0; i < tableSize; i++) {
n = table[i];
while(n) {
l.append(n->key);
n = n->next;
}
}
traverse(root, l);
return l;
}
......@@ -97,32 +76,48 @@ QStringList SortedStringList::values() const
// private methods
////////////////////////////////////////////////////////////////////////////////
int SortedStringList::hash(const QString &key) const
bool SortedStringList::BSTInsert(const QString &value)
{
uint h = 0;
uint g;
const QChar *p = key.unicode();
for(int i = 0; i < int(key.length()); i++) {
h = (h << 4) + p[i].cell();
if((g = h & 0xf0000000))
h ^= g >> 24;
h &= ~g;
Node *previousNode = 0;
Node *node = root;
while(node) {
previousNode = node;
if(value < node->key)
node = node->left;
else
node = node->right;
}
if(previousNode && value == previousNode->key)
return true;
int index = h;
Node *n = new Node(value);
if(index < 0)
index = -index;
n->parent = previousNode;
return(index % tableSize);
if(!root)
root = n;
else {
if(value < previousNode->key) {
previousNode->left = n;
// kdDebug() << "LEFT - " << value << endl;
}
else {
previousNode->right = n;
// kdDebug() << "RIGHT - " << value << endl;
}
}
return false;
}
void SortedStringList::deleteNode(Node *n)
void SortedStringList::traverse(const Node *n, QStringList &list) const
{
if(n) {
deleteNode(n->next);
delete(n);
}
if(!n)
return;
traverse(n->left, list);
list.append(n->key);
traverse(n->right, list);
}
......@@ -20,7 +20,6 @@
#include <qstring.h>
#include <qstringlist.h>
#include <qptrvector.h>
class SortedStringList
{
......@@ -40,10 +39,15 @@ public:
private:
class Node;
int hash(const QString &key) const;
void deleteNode(Node *n);
QPtrVector<Node> table;
/**
* The insertion implementation. Returns true if the item was already
* present in the list.
*/
bool BSTInsert(const QString &value);
void traverse(const Node *n, QStringList &list) const;
Node *root;
};
#endif
/***************************************************************************
stringhash.cpp - description
-------------------
begin : Sun Feb 2 2003
copyright : (C) 2003 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#include "stringhash.h"
static const int tableSize = 5003;
class StringHash::Node
{
public:
Node(const QString &value) : key(value), next(0) {}
~Node() {}
QString key;
Node *next;
};
StringHash::StringHash() : table(tableSize)
{
}
StringHash::~StringHash()
{
for(int i = 0; i < tableSize; i++)
deleteNode(table[i]);
}
bool StringHash::insert(const QString &value)
{
int h = hash(value);
Node *i = table[h];
Node *j = 0;
while(i) {
if(i->key == value)
return true;
else {
j = i;
i = i->next;
}
}
if(j)
j->next = new Node(value);
else
table.insert(h, new Node(value));
return false;
}
bool StringHash::contains(const QString &value) const
{
int h = hash(value);
Node *i = table[h];
while(i && i->key != value)
i = i->next;
return bool(i);
}
/*
QStringList StringHash::values() const
{
QStringList l;
Node *n;
for(int i = 0; i < tableSize; i++) {
n = table[i];
while(n) {
l.append(n->key);
n = n->next;
}
}
return l;
}
*/
////////////////////////////////////////////////////////////////////////////////
// private methods
////////////////////////////////////////////////////////////////////////////////
int StringHash::hash(const QString &key) const
{
uint h = 0;
uint g;
const QChar *p = key.unicode();
for(int i = 0; i < int(key.length()); i++) {
h = (h << 4) + p[i].cell();
if((g = h & 0xf0000000))
h ^= g >> 24;
h &= ~g;
}
int index = h;
if(index < 0)
index = -index;
return(index % tableSize);
}
void StringHash::deleteNode(Node *n)
{
if(n) {
deleteNode(n->next);
delete(n);
}
}
/***************************************************************************
stringhash.h - description
-------------------
begin : Sun Feb 2 2003
copyright : (C) 2003 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef STRINGHASH_H
#define STRINGHASH_H
#include <qstring.h>
#include <qstringlist.h>
#include <qptrvector.h>
class StringHash
{
public:
StringHash();
~StringHash();
bool insert(const QString &value);
bool contains(const QString &value) const;
/**
* Returns a sorted list of the values.
* Warning, this method is expensive and shouldn't be used except when
* necessary.
*/
// QStringList values() const;
private:
class Node;
int hash(const QString &key) const;
void deleteNode(Node *n);
QPtrVector<Node> table;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment