杂乱1

本文介绍了一个基于HBase的查询系统实现方案,通过动态树形菜单展示具体数据查询和数据量查询等功能,并详细解释了菜单点击事件、数据表格转换为JSON字符串以及字符串转换回数据表格的过程。
$(function () {  
    //动态树形菜单数据  
    var treeData = [{  
          text : "Hbase查询功能列表",  
          children : [{  
                  text : "具体数据查询",  
                  children : [{  
                          text : "单一商品价格库存",  
                          attributes : {  
                              url : '<iframe width="100%" height="100%" frameborder="0"  src="jsp/queryPriceStock.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'  
                          }  
                      }, {  
                          text : "单一商品价格库存2",  
                          attributes : {  
                              url : ''  
  
                          }  
                      }  
                  ]  
              },{  
                  text : "数据量查询",  
                  children : [{  
                          text : "总量统计",  
                          attributes : {  
                              url : '<iframe width="100%" height="100%" frameborder="0"  src="jsp/queryPriceStock.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'  
                          }  
                      }, {  
                          text : "总量统计2",  
                          attributes : {  
                              url : ''  
                          }  
                      }  
                  ]  
              }  
          ]  
      }  
  ];  
      
    //实例化树形菜单  
    $("#tree").tree({  
        data : treeData,  
        lines : true,  
        onClick : function (node) {  
            if (node.attributes) {  
                Open(node.text, node.attributes.url);  
            }  
        }  
    });  
    //在右边center区域打开菜单,新增tab  
    function Open(text, url) {  
        if ($("#tabs").tabs('exists', text)) {  
            $('#tabs').tabs('select', text);  
        } else {  
            $('#tabs').tabs('add', {  
                title : text,  
                closable : true,  
                content : url  
            });  
        }  
    }  
      
    //绑定tabs的右键菜单  
    $("#tabs").tabs({  
        onContextMenu : function (e, title) {  
            e.preventDefault();  
            $('#tabsMenu').menu('show', {  
                left : e.pageX,  
                top : e.pageY  
            }).data("tabTitle", title);  
        }  
    });  
      
    //实例化menu的onClick事件  
    $("#tabsMenu").menu({  
        onClick : function (item) {  
            CloseTab(this, item.name);  
        }  
    });  
      
    //几个关闭事件的实现  
    function CloseTab(menu, type) {  
        var curTabTitle = $(menu).data("tabTitle");  
        var tabs = $("#tabs");  
          
        if (type === "close") {  
            tabs.tabs("close", curTabTitle);  
            return;  
        }  
          
        var allTabs = tabs.tabs("tabs");  
        var closeTabsTitle = [];  
          
        $.each(allTabs, function () {  
            var opt = $(this).panel("options");  
            if (opt.closable && opt.title != curTabTitle && type === "Other") {  
                closeTabsTitle.push(opt.title);  
            } else if (opt.closable && type === "All") {  
                closeTabsTitle.push(opt.title);  
            }  
        });  
          
        for (var i = 0; i < closeTabsTitle.length; i++) {  
            tabs.tabs("close", closeTabsTitle[i]);  
        }  
    }  
});  






/// <summary>
        /// Msdn
        /// </summary>
        /// <param name="jsonName"></param>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static string DataTableToJson(string jsonName, DataTable dt)
        {
            StringBuilder Json = new StringBuilder();
            Json.Append("{\"" + jsonName + "\":[");
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Json.Append("{");
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        Json.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":\"" + dt.Rows[i][j].ToString() + "\"");
                        if (j < dt.Columns.Count - 1)
                        {
                            Json.Append(",");
                        }
                    }
                    Json.Append("}");
                    if (i < dt.Rows.Count - 1)
                    {
                        Json.Append(",");
                    }
                }
            }
            Json.Append("]}");
            return Json.ToString();
        }
    }




<table>  
                                <tr>  
                                    <td>  
                                        <div>部门名称: </div>  
                                        <select style="margin-bottom: 20px; margin-right: 20px; width: 200px; height: 32px;" class="easyui-combotree" id="seleDepartName" name="city" />  
                                    </td>  
                                    <td>  
                                        <div>  
                                            <div>公司:</div>  
                                            <input style="margin-bottom: 20px; margin-right: 20px; width: 200px; height: 32px;" id="seleCompanyId" class="easyui-combobox"  
                                                   name="language"  
                                                   data-options="  
                                                url:'../api/xxx',  
                                                method:'get',  
                                                valueField:'CompanyId',  
                                                textField:'CompanyName',  
                                                panelHeight:'auto',  
                                                   editable:false,  
                                                   required:true">  
                                        </div>  
                                    </td>  
                                </tr>  
                                <tr>  
  
                                    <td>  
                                        <div style="float: none; width:  200px; margin-top: 50px;">  
                                            <div>  
                                                <a href="#" class="easyui-linkbutton" id="btnSubmit" style="width: 100%; height: 32px">提交</a>  
                                            </div>  
                                        </div>  
                                    </td>  
                                </tr>  
                            </table>  






$('#seleDepartName').combotree({  
           url: "../Depart/Test",  
           method: 'get',  
           loadFilter: function (rows) {  
               return convert(rows);  
           }  
       });  






function convert(rows) {  
            function exists(rows, ParentDepartId) {  
                for (var i = 0; i < rows.length; i++) {  
                    if (rows[i].DepartId === ParentDepartId) return true;  
                }  
                return false;  
            }  
  
            debugger;  
            var nodes = [];  
            // get the top level nodes  
            for (var i = 0; i < rows.length; i++) {  
                var row = rows[i];  
                if (!exists(rows, row.ParentDepartId)) {  
                    nodes.push({  
                        id: row.DepartId,  
                        text: row.DepartName  
                    });  
                }  
            }  
  
            var toDo = [];  
            for (var i = 0; i < nodes.length; i++) {  
                toDo.push(nodes[i]);  
            }  
            while (toDo.length) {  
                var node = toDo.shift();    // the parent node  
                // get the children nodes  
                for (var i = 0; i < rows.length; i++) {  
                    var row = rows[i];  
                    if (row.ParentDepartId == node.id) {  
                        var child = { id: row.DepartId, text: row.DepartName };  
                        if (node.children) {  
                            node.children.push(child);  
                        } else {  
                            node.children = [child];  
                        }  
                        toDo.push(child);  
                    }  
                }  
            }  
            return nodes;  
        }  






function myformatter(date){  
    var y = date.getFullYear();  
    var m = date.getMonth()+1;  
    var d = date.getDate();  
    return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);  
}  
          
function myparser(s){  
    if (!s) return new Date();  
    var ss = (s.split('-'));  
    var y = parseInt(ss[0],10);  
    var m = parseInt(ss[1],10);  
    var d = parseInt(ss[2],10);  
    if (!isNaN(y) && !isNaN(m) && !isNaN(d)){  
        return new Date(y,m-1,d);  
    } else {  
        return new Date();  
    }  
}  
  
//页面加载  
$(function(){  
    //设置时间  
   var curr_time = new Date();     
   $("#txtBeginTime").datebox("setValue",myformatter(curr_time));  
   $("#txtEndTime").datebox("setValue",myformatter(curr_time));  
   //获取时间  
   var beginTime=$("#txtBeginTime").datebox("getValue");  
   var endTime=$("#txtEndTime").datebox("getValue");  
});  




$('#tt').datagrid({    
    title:'Frozen Columns',    
    iconCls:'icon-save',    
    width:500,    
    height:250,    
    url:'data/datagrid_data.json',    
    frozenColumns:[[    
        {field:'itemid',title:'Item ID',width:80},    
        {field:'productid',title:'Product ID',width:80},    
    ]],    
    columns:[[    
        {field:'listprice',title:'List Price',width:80,align:'right'},    
        {field:'unitcost',title:'Unit Cost',width:80,align:'right'},    
        {field:'attr1',title:'Attribute',width:100},    
        {field:'status',title:'Status',width:60}    
    ]]    
});  




DataTable到string         


        /// <summary>
        /// DataTable 到 string
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static string DataTableToString(DataTable dt)
        {
            //!@&,#$%,^&*为字段的拼接字符串
            //为了防止连接字符串不在DataTable数据中存在,特意将拼接字符串写成特殊的字符!
            StringBuilder strData = new StringBuilder();
            StringWriter sw = new StringWriter();


            //DataTable 的当前数据结构以 XML 架构形式写入指定的流
            dt.WriteXmlSchema(sw);
            strData.Append(sw.ToString());
            sw.Close();
            strData.Append("@&@");
            for (int i = 0; i < dt.Rows.Count; i++)           //遍历dt的行
            {
                DataRow row = dt.Rows[i];
                if (i > 0)                                    //从第二行数据开始,加上行的连接字符串
                {
                    strData.Append("#$%");
                }
                for (int j = 0; j < dt.Columns.Count; j++)    //遍历row的列
                {
                    if (j > 0)                                //从第二个字段开始,加上字段的连接字符串
                    {
                        strData.Append("^&*");
                    }
                    strData.Append(Convert.ToString(row[j])); //取数据
                }
            }


            return strData.ToString();
        }


 string到DataTable


        /// <summary>
        /// string 到 DataTable
        /// </summary>
        /// <param name="strdata"></param>
        /// <returns></returns>
        public static DataTable StringToDataTable(string strdata)
        {
            if (string.IsNullOrEmpty(strdata))
            {
                return null;
            }
            DataTable dt = new DataTable();
            string[] strSplit = { "@&@" };
            string[] strRow = { "#$%" };    //分解行的字符串
            string[] strColumn = { "^&*" }; //分解字段的字符串


            string[] strArr = strdata.Split(strSplit, StringSplitOptions.None);
            StringReader sr = new StringReader(strArr[0]);
            dt.ReadXmlSchema(sr);
            sr.Close();




            string strTable = strArr[1]; //取表的数据
            if (!string.IsNullOrEmpty(strTable))
            {
                string[] strRows = strTable.Split(strRow, StringSplitOptions.None); //解析成行的字符串数组
                for (int rowIndex = 0; rowIndex < strRows.Length; rowIndex++)       //行的字符串数组遍历
                {
                    string vsRow = strRows[rowIndex]; //取行的字符串
                    string[] vsColumns = vsRow.Split(strColumn, StringSplitOptions.None); //解析成字段数组
                    dt.Rows.Add(vsColumns);
                }
            }
            return dt;
        }    

<think>好的,我现在需要帮助用户解决他们关于“杂乱计数 算法 数据结构”的问题。首先,我要理解用户的问题到底是什么。用户提到的“杂乱计数”可能是指某种特定的计数方法或算法,但这个词并不是标准的术语,所以需要结合他们提供的引用内容来推断。 查看用户提供的引用,特别是引用[3]和引用[4],其中提到了基数排序和希尔排序的时间复度,以及计数排序的相关信息。用户可能在询问与计数相关的排序算法,比如计数排序、基数排序,或者哈希表这样的数据结构。引用[4]提到基数排序的时间复度和空间复度,以及它适用于整数排序,这可能与计数有关。 接下来,我需要确认用户的问题是否与计数排序(Counting Sort)有关。计数排序是一种非比较排序算法,适用于整数且范围不大的情况,它的核心是使用一个计数数组来记录每个元素的出现次数。这可能与用户提到的“杂乱计数”相关,尤其是引用了基数排序和计数数组的部分。 然后,用户的问题还涉及数据结构和算法,因此需要将计数排序与数据结构(如数组、哈希表)联系起来。引用[1]中提到的哈希表(散列表/Map)可能也是相关的,因为哈希表常用于快速查找和计数。 接下来,我需要整理这些信息,确保回答结构清晰,符合用户的要求:使用中文,行内公式用$...$,独立公式用$$...$$,正确引用标注,并生成相关问题。同时,回答需要覆盖算法原理、数据结构应用、时间复度分析以及代码示例。 现在要检查是否有遗漏的信息或可能的误解。用户提到的“杂乱计数”可能是指处理杂乱数据的计数方法,或者是将计数应用于不同数据结构的算法。需要明确回答计数排序及其相关数据结构,可能涉及基数排序和哈希表的使用。 最后,确保引用的正确应用,每个引用在适当的位置添加标识,例如在提到时间复度分析时引用[2],在讨论基数排序时引用[4],在涉及数据结构时引用[1]。 总结回答的结构:首先解释计数排序的原理和数据结构,然后讨论其时间复度和应用场景,接着提供代码示例,最后生成相关问题。</think>### 杂乱计数算法与数据结构解析 #### 1. 计数排序(Counting Sort) **原理** 计数排序是一种非比较型整数排序算法,核心思想是通过统计元素出现次数实现排序。其步骤如下: 1. 统计数组中每个元素$k$的出现次数,存入计数数组`count[k]` 2. 对计数数组累加,得到每个元素在排序后数组中的最终位置 3. 反向遍历原数组,根据计数数组将元素放入正确位置 **数据结构** - **计数数组**:用于记录元素频率,空间复度为$O(k)$,其中$k$是元素取值范围[^4] - **临时数组**:存储排序结果,空间复度为$O(n)$ **时间复度** - 平均时间复度为$O(n + k)$,适用于元素范围较小的情况[^2] ```python def counting_sort(arr): max_val = max(arr) count = [0] * (max_val + 1) output = [0] * len(arr) for num in arr: count[num] += 1 for i in range(1, len(count)): count[i] += count[i-1] for num in reversed(arr): output[count[num]-1] = num count[num] -= 1 return output ``` #### 2. 基数排序(Radix Sort)中的计数应用 基数排序利用计数排序作为子过程,按位进行排序: - **核心操作**:对每一位使用计数排序,时间复度为$O(d(n + k))$,其中$d$是最大位数[^4] - **适用场景**:整数排序,尤其适合位数较少的数字集合 #### 3. 哈希表与计数 哈希表(散列表)常用于快速统计元素频率: - **应用示例**:统计词频时,键为单词,值为出现次数 - **时间复度**:插入和查询操作平均为$O(1)$[^1] #### 4. 性能对比 | 算法 | 时间复度 | 空间复度 | 稳定性 | |------------|-----------------|------------|--------| | 计数排序 | $O(n + k)$ | $O(n + k)$ | 稳定 | | 基数排序 | $O(d(n + k))$ | $O(n + k)$ | 稳定 | | 哈希表计数 | $O(n)$ | $O(n)$ | 不适用 |
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值