⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transactionlist.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
字号:
/*
 *    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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/**
 * Title: XELOPES Data Mining Library
 * Description: The XELOPES library is an open platform-independent and data-source-independent library for Embedded Data Mining.
 * Copyright: Copyright (c) 2002 Prudential Systems Software GmbH
 * Company: ZSoft (www.zsoft.ru), Prudsys (www.prudsys.com)
 * @author Victor Borichev
 * @author Valentine Stepanenko (valentine.stepanenko@zsoft.ru)
 * @version 1.0
 */

package com.prudsys.pdm.Models.Sequential.Algorithms.Seq;


/**
 * Transactions id list
 * Stores transactions id assuming an ascending order
 *
 * @author ZSoft
 * @version 1.0
 */

public class TransactionList {

  /** vector's capacity */
  private int capacity;
  /** number of transaction id's */
  private int transNum;
  /** transactions id's */
  private int[] transList;

  /**
   * Default constructor
   */
  TransactionList() {
    transList = new int[10];
    transNum = 0;
    capacity = 10;
  }
  /**
   * Constructor from array
   * @param invals array of transaction id's
   */
  TransactionList(int[] invals) {
    transList = new int[invals.length];
    for(int i = 0; i < invals.length; i++) transList[i] = invals[i];
    transNum = capacity = invals.length;
  }
  /**
   * add transaction id to end of the list
   * When maximum capacity will be reached new memory for the list
   * will reallocate
   * @param tid transaction id
   */
  void addTransaction(int tid) {
    if(transNum==capacity) {
      capacity *= 10;
      int[] newtl = new int[capacity];
      System.arraycopy(transList,0,newtl,0,transNum);
      transList = newtl;
    }
    transList[transNum] = tid;
    transNum++;
  }
  /**
   * make intersection of this transaction list with transaction list of tl
   * result saved in newtl
   * @param tl second operand of intersection
   * @param newtl result of operation
   */
  void intersection(TransactionList tl, TransactionList newtl)
  {
    int i, ab = 1;
    int apos, bpos, trans, r;
    apos = 0; bpos = 0;
    newtl.clear();
    while(apos<transNum&&bpos<tl.transNum)
    {
      if(ab==1)
      {
        trans = transList[apos];
        for(i=bpos,r=-1;i<tl.transNum&&r<trans;i++)
          r = tl.transList[i];
          bpos = i-1;
          apos++;
        if(r == trans) {
          newtl.addTransaction(trans);
          bpos++;
          continue;
        } else ab = 1 - ab;
      } else
      {
        trans = tl.transList[bpos];
        for(i=apos,r=-1;i<transNum&&r<trans;i++)
          r = transList[i];
          apos = i-1;
          bpos++;
        if(r == trans) {
          newtl.addTransaction(trans);
          apos++;
          continue;
        } else ab = 1 - ab;
      }
    }
  }

  /**
   * Set current size of transactions list
   * @param len new length of transactions list
   */
  void setSize(int len)
  {
    transNum = len;
  }
  /**
   * return length of transactions list
   * @return length
   */
  int getSize() {
    return transNum;
  }
  /**
   * set transaction id at specified position
   * @param tid transaction id
   * @param n position
   */
  void setTransaction(int tid, int n)
  {
    transList[n] = tid;
  }
  /**
   * get transaction id at position n
   * @param n position of transaction id to return
   * @return transaction id
   */
  int getTransaction(int n) {
    if(transNum!=0) return transList[n];
    return -1;
  }
  /**
   * make copy of transaction list
   * @param tl transaction list to copy into
   */
  void copy(TransactionList tl) {
    tl.transNum = tl.capacity = transNum;
    tl.transList = new int[transNum];
    System.arraycopy(transList,0,tl.transList,0,transNum);
  }
  /**
   * reset transaction id's counter in zero. no memory reallocation occures
   */
  void clear() {
    transNum = 0;
  }
  /**
   * print transaction id's
   */
  void print() {
    System.out.print("TL:\t");
    for(int i=0;i<transNum;i++) System.out.print(transList[i]+"\t");
    System.out.println();
  }

  public static void main(String[] args) {
    int[] ain = {0,4,5,9,12,14,15,45,67,90,125,189,210,222};
    int[] bin = {2,4,7,9,10,11,12,13,14,45,56,66,67,90,94,122,125,189};
    TransactionList a = new TransactionList(ain);
    TransactionList b = new TransactionList(bin);
    TransactionList c = new TransactionList();
    a.print();
    b.print();
    a.intersection(b,c);
    c.print();
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -