当前位置: 首页>>代码示例>>Java>>正文


Java BitSet.size方法代码示例

本文整理汇总了Java中java.util.BitSet.size方法的典型用法代码示例。如果您正苦于以下问题:Java BitSet.size方法的具体用法?Java BitSet.size怎么用?Java BitSet.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.BitSet的用法示例。


在下文中一共展示了BitSet.size方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAssignmentsNumber

import java.util.BitSet; //导入方法依赖的package包/类
static long getAssignmentsNumber(BitSet[] studentsPreferences, int studentIndex, BitSet unavailableTasks) {
	if (studentIndex < 0) {
		return 1;
	}

	long result = 0;
	BitSet currStudentPreferences = studentsPreferences[studentIndex];
	for (int i = 0; i < currStudentPreferences.size(); i++) {
		if (currStudentPreferences.get(i) && !unavailableTasks.get(i)) {
			unavailableTasks.set(i, true);
			result += getAssignmentsNumber(studentsPreferences, studentIndex - 1, unavailableTasks);
			unavailableTasks.set(i, false);
		}
	}

	return result;
}
 
开发者ID:lagodiuk,项目名称:spoj,代码行数:18,代码来源:ASSIGN.java

示例2: containChars

import java.util.BitSet; //导入方法依赖的package包/类
/**
 * 求一个字符串包含的char
 * 
 */
public static void containChars(String str) {
	BitSet used = new BitSet();
	for (int i = 0; i < str.length(); i++)
		used.set(str.charAt(i)); // set bit for char

	StringBuilder sb = new StringBuilder();
	sb.append("[");
	int size = used.size();
	System.out.println(size);
	for (int i = 0; i < size; i++) {
		if (used.get(i)) {
			sb.append((char) i);
		}
	}
	sb.append("]");
	System.out.println(sb.toString());
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:22,代码来源:BitSetDemo.java

示例3: computePrime

import java.util.BitSet; //导入方法依赖的package包/类
/**
 * 求素数 有无限个。一个大于1的自然数,如果除了1和它本身外,不能被其他自然数整除(除0以外)的数称之为素数(质数) 否则称为合数
 */
public static void computePrime() {
	BitSet sieve = new BitSet(1024);
	int size = sieve.size();
	for (int i = 2; i < size; i++)
		sieve.set(i);
	int finalBit = (int) Math.sqrt(sieve.size());

	for (int i = 2; i < finalBit; i++)
		if (sieve.get(i))
			for (int j = 2 * i; j < size; j += i)
				sieve.clear(j);

	int counter = 0;
	for (int i = 1; i < size; i++) {
		if (sieve.get(i)) {
			System.out.printf("%5d", i);
			if (++counter % 15 == 0)
				System.out.println();
		}
	}
	System.out.println();
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:26,代码来源:BitSetDemo.java

示例4: firstDate

import java.util.BitSet; //导入方法依赖的package包/类
protected static Date firstDate(DatePattern dp, int dayCode) {
   	if (dp == null) return null;
   	BitSet weekCode = dp.getPatternBitSet();
   	if (weekCode.isEmpty()) return null;
   	Calendar cal = Calendar.getInstance(Locale.US); cal.setLenient(true);
   	Date dpFirstDate = DateUtils.getDate(1, dp.getSession().getPatternStartMonth(), dp.getSession().getSessionStartYear());
   	cal.setTime(dpFirstDate);
   	int idx = weekCode.nextSetBit(0);
   	cal.add(Calendar.DAY_OF_YEAR, idx);
   	while (idx < weekCode.size()) {
   		if (weekCode.get(idx)) {
       		int dow = cal.get(Calendar.DAY_OF_WEEK);
       		switch (dow) {
       		case Calendar.MONDAY:
       			if ((dayCode & DayCode.MON.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.TUESDAY:
       			if ((dayCode & DayCode.TUE.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.WEDNESDAY:
       			if ((dayCode & DayCode.WED.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.THURSDAY:
       			if ((dayCode & DayCode.THU.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.FRIDAY:
       			if ((dayCode & DayCode.FRI.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.SATURDAY:
       			if ((dayCode & DayCode.SAT.getCode()) != 0) return cal.getTime();
       			break;
       		case Calendar.SUNDAY:
       			if ((dayCode & DayCode.SUN.getCode()) != 0) return cal.getTime();
       			break;
       		}
       	}
   		cal.add(Calendar.DAY_OF_YEAR, 1); idx++;
   	}
   	return null;
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:41,代码来源:InstructorScheduleConnector.java

示例5: d

import java.util.BitSet; //导入方法依赖的package包/类
/**
 * Returns Hamming distance between the two BitSets.
 */
public static int d(BitSet x, BitSet y) {
    if (x.size() != y.size())
        throw new IllegalArgumentException(String.format("BitSets have different length: x[%d], y[%d]", x.size(), y.size()));

    int dist = 0;
    for (int i = 0; i < x.size(); i++) {
        if (x.get(i) != y.get(i))
            dist++;
    }

    return dist;
}
 
开发者ID:takun2s,项目名称:smile_1.5.0_java7,代码行数:16,代码来源:HammingDistance.java

示例6: jaccardSimilarity

import java.util.BitSet; //导入方法依赖的package包/类
public static double jaccardSimilarity(BitSet b1, BitSet b2) {
	BitSet bs = new BitSet(b1.size());
	bs.or(b1);
	bs.and(b2);
	double intersection = bs.cardinality();
	bs.clear();
	bs.or(b1);
	bs.or(b2);
	double union = bs.cardinality();
	return intersection / union;
}
 
开发者ID:ag-sc,项目名称:JLink,代码行数:12,代码来源:JaccardSimilarities.java

示例7: bitSet2ByteArray

import java.util.BitSet; //导入方法依赖的package包/类
/**
 * 将BitSet对象转化为ByteArray
 * @param bitSet
 * @return
 */
public static byte[] bitSet2ByteArray(BitSet bitSet) {
       byte[] bytes = new byte[bitSet.size() / 8];
       for (int i = 0; i < bitSet.size(); i++) {
           int index = i / 8;
           int offset = 7 - i % 8;
           bytes[index] |= (bitSet.get(i) ? 1 : 0) << offset;
       }
       return bytes;
   }
 
开发者ID:juebanlin,项目名称:util4j,代码行数:15,代码来源:BitSetDemo.java

示例8: anyValueSet

import java.util.BitSet; //导入方法依赖的package包/类
/**
 * Returns <code>true</code> iff any bit in the given set is
 * <code>true</code>.
 */
private boolean anyValueSet(final BitSet set) {
    for (int i = 0; i < set.size(); i++) {
        if (set.get(i)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:funkemunky,项目名称:HCFCore,代码行数:13,代码来源:CollatingIterator.java

示例9: main

import java.util.BitSet; //导入方法依赖的package包/类
public static void main(String[] args)
{
   // get input integer
   Scanner scanner = new Scanner(System.in);
   System.out.println("Please enter an integer from 2 to 1023");
   int input = scanner.nextInt();

   // perform Sieve of Eratosthenes
   BitSet sieve = new BitSet(1024);
   int size = sieve.size(); 

   // set all bits from 2 to 1023
   for (int i = 2; i < size; i++)
      sieve.set(i);

   // perform Sieve of Eratosthenes
   int finalBit = (int) Math.sqrt(size);

   for (int i = 2; i < finalBit; i++) 
   {
      if (sieve.get(i)) 
      {
         for (int j = 2 * i; j < size; j += i) 
            sieve.clear(j);
      } // end if
   } // end for

   int counter = 0; 

   // display prime numbers from 2 to 1023
   for (int i = 2; i < size; i++)
   {
      if (sieve.get(i)) 
      {
         System.out.print(String.valueOf(i));
         System.out.print(++counter % 7 == 0 ? "\n" : "\t");
      } // end if
   } // end for

   // display result
   if (sieve.get(input))
      System.out.printf("\n%d is a prime number", input);
   else
      System.out.printf("\n%d is not a prime number", input);
}
 
开发者ID:cleitonferreira,项目名称:LivroJavaComoProgramar10Edicao,代码行数:46,代码来源:BitSetTest.java

示例10: failureDiagnostic

import java.util.BitSet; //导入方法依赖的package包/类
/**
 * Performs a short failure diagnostic.
 * 
 * @param annotation
 *            The failure annotation.
 * @param join
 *            The join node with a potential deadlock.
 * @param from
 *            The incoming edge of the dominator (or the start edge)
 * @param out
 *            The outgoing edge of the join node.
 * @param information
 *            Information of visible edges.
 */
private void failureDiagnostic(DeadlockAnnotation annotation, WGNode join, Edge from, Edge out,
		BitSet information) {
	// Determine for each reached incoming edge of this
	// join node a path to the join.
	BitSet incomeJoin = (BitSet) incoming[join.getId()].clone();

	// Regard only the edges which arrive at the start edge.
	incomeJoin.and(information);
	// For each incoming edge calculate the paths
	for (int inEdge = incomeJoin.nextSetBit(0); inEdge >= 0; inEdge = incomeJoin.nextSetBit(inEdge + 1)) {

		// Create a new path/visited set
		BitSet vis = new BitSet(incomeJoin.size());
		// Determine split or or-splits
		List<WGNode> splits = new ArrayList<WGNode>();
		// Determine the path to the join
		getPathsToJoin(from.id, inEdge, vis, splits);
		BitSet v = new BitSet(incomeJoin.size());
		inverseDepthFirstSearch(inEdge, from.id, vis, v);
		// Add the path to the failure annotation
		annotation.addPathToFailure(v);

		// Determine each (or-)split whose successors
		// are appr. exec. edges however not its incoming
		// edge
		for (WGNode split : splits) {
			// Get a copy of the outgoing edges
			BitSet outgo = (BitSet) outgoing[split.getId()].clone();
			outgo.and(out.isApproxExecutedBy);

			if (outgo.cardinality() < outgoing[split.getId()].cardinality()) {

				// It is a failure node
				annotation.addFailureNode(split);

			}
		}
	}

	annotation.addPrintableNode(join);
	annotation.addOpeningNode(from.tgt);

	// Delete the other incoming edge of this join from the
	// start edge information to avoid double failures
	information.andNot(incomeJoin);
}
 
开发者ID:guybrushPrince,项目名称:mojo.core,代码行数:61,代码来源:DeadlockAnalysis.java


注:本文中的java.util.BitSet.size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。