Changeset 31654

Show
Ignore:
Timestamp:
03/29/09 12:43:45 (4 years ago)
Author:
hoge1e3
Message:

ナイーブな検索スピードアップ

Location:
lang/csharp/soyText/soyText
Files:
1 added
7 modified

Legend:

Unmodified
Added
Removed
  • lang/csharp/soyText/soyText/Document.cs

    r31620 r31654  
    6464            tx.Write(content); 
    6565            tx.Close(); 
     66            _lastUpdate = null; 
    6667        } 
    6768        public Boolean isNew 
     
    9596            get { return documentSet.getFileName(handle, state); } 
    9697        } 
    97         public DateTime lastUpdate 
     98        long? _lastUpdate = null; 
     99        public long lastUpdate 
    98100        { 
    99101            get 
    100102            { 
    101                 return File.GetLastWriteTime(fileName); 
     103                if (_lastUpdate != null) return (long)_lastUpdate; 
     104                return (long)(_lastUpdate = File.GetLastWriteTime(fileName).Ticks); 
    102105            } 
    103106        } 
  • lang/csharp/soyText/soyText/DocumentSet.cs

    r31517 r31654  
    3434        public int byRecency(Document d1, Document d2) 
    3535        { 
    36             long d = d1.lastUpdate.Ticks - d2.lastUpdate.Ticks; 
     36            long d = d1.lastUpdate - d2.lastUpdate; 
    3737            return (d == 0 ? 0 : (d < 0 ? 1 : -1)); 
    3838        } 
    3939        public List<Document> getRecents() 
    4040        { 
     41            Debug.print("文書一覧取得中..."); 
    4142            var res = new List<Document>(); 
    4243            foreach (string fileName 
     
    4950                res.Add(createDocument(handle)); 
    5051            } 
     52            Debug.print("文書一覧並べ替え中..."); 
    5153            res.Sort(byRecency);/* delegate(Document d1, Document d2) 
    5254            { 
     
    6769            var t = workspace.indexer.createToken(kw); 
    6870            var res = new HashSet<Document>(); 
    69  
     71            Debug.print("文字検索: " + kw); 
    7072            foreach (var st in t.existentSuperstrings) 
    7173            { 
    7274                res.UnionWith(exactSearch(st)); 
     75            } 
     76            Debug.print("activeな文書を検索: " + kw); 
     77            foreach (var d in getRecents()) 
     78            { 
     79                if (d.matches(kw)) res.Add(d); 
    7380            } 
    7481            /* 
     
    9299            }*/ 
    93100            var resList = res.ToList(); 
     101            Debug.print("検索結果の並べ替え: "+kw); 
    94102            resList.Sort(byRecency); 
     103            Debug.print("End: 検索結果の並べ替え: " + kw); 
    95104            return resList; 
    96105            //return getRecents().FindAll(d => d.matches(kw)); 
  • lang/csharp/soyText/soyText/Form1.cs

    r31620 r31654  
    1414namespace SoyText 
    1515{ 
     16    public delegate void SyncUIAction();  
    1617    public partial class Form1 : Form 
    1718    { 
     
    2122        public static Form1 defaultInstance; 
    2223        String _statusText = ""; 
     24        Queue<SyncUIAction> uiActionQueue=new Queue<SyncUIAction>(); 
    2325        public String statusText 
    2426        { 
     
    5557        } 
    5658        IEnumerator<int> listings; 
     59        public DocumentSet documentSet 
     60        { 
     61            get { return workspace.documentSet; } 
     62        } 
    5763        public void refreshList() 
    5864        { 
    59            //docList.Items.Clear(); 
    60            docListBox.Items.Clear(); 
    61             listings = refreshListLoop(null); 
    62         } 
    63         public DocumentSet documentSet 
    64         { 
    65             get { return workspace.documentSet; } 
    66         } 
    67         public IEnumerator<int> refreshListLoop(String kw) { 
    68             var cnt = 0; 
    69             foreach (Document d in  documentSet.search(kw)) 
    70             { 
    71                 //var i = docList.Items.Add("" + d.handle); 
    72                 if (kw==null || d.matches(kw)) 
    73                 { 
    74                     docListBox.Items.Add(d);//"" + d.handle); 
     65            refreshList(null); 
     66        } 
     67        public void refreshList(String kw) { 
     68            new Thread(delegate() 
     69            { 
     70                var cnt = 0; 
     71                var res = documentSet.search(kw); 
     72                syncUI(delegate() 
     73                { 
     74                    docListBox.Items.Clear(); 
     75                }); 
     76                foreach (Document d in res) 
     77                { 
     78                    //var i = docList.Items.Add("" + d.handle); 
     79                    var d2 = d; 
     80                    //if (kw == null || d.matches(kw)) 
     81                    //{ 
     82                        syncUI(delegate() 
     83                        { 
     84                            docListBox.Items.Add(d2); 
     85                        }); 
     86                    //} 
     87                    Thread.Sleep(1); 
     88                    //if (cnt % 10 == 0) yield return 0; 
     89                    cnt++; 
     90                    if (cnt > 100) break; 
    7591                } 
    76                 if (cnt % 10 == 0) yield return 0; 
    77                 cnt++; 
    78                 if (cnt > 100) yield break; 
    79             } 
    80         } 
    81  
     92                statusText = "完了"; 
     93            }).Start(); 
     94        } 
     95        public void syncUI(SyncUIAction u) 
     96        { 
     97            uiActionQueue.Enqueue(u); 
     98        } 
    8299        private void newDocument() 
    83100        { 
     
    103120            if (e.KeyCode.Equals(Keys.Enter)) 
    104121            { 
    105                 var s=documentSet.search(command.Text); 
    106                 docListBox.Items.Clear(); 
    107                 listings = refreshListLoop(command.Text); 
     122                //var s=documentSet.search(command.Text); 
     123                refreshList(command.Text); 
    108124                /* 
    109125                var lim = 100; 
     
    132148                    listings = null; 
    133149                } 
     150            } 
     151            //Text = "" + uiActionQueue.Count; 
     152            while (uiActionQueue.Count > 0) 
     153            { 
     154                uiActionQueue.Dequeue().Invoke(); 
    134155            } 
    135156        } 
  • lang/csharp/soyText/soyText/Token.cs

    r31441 r31654  
    9595        {  
    9696            get { 
     97                if (!File.Exists(superstringPath)) return 0; 
    9798                return new FileInfo(superstringPath).Length; 
    9899            } 
     
    139140                { 
    140141                    if (content.Length == 1) return res; 
    141  
     142                     
    142143                    var ct = mostRareChar; 
    143144                    foreach (var t in ct.existentSuperstrings) 
  • lang/csharp/soyText/soyText/soyText.csproj

    r31588 r31654  
    4949  </ItemGroup> 
    5050  <ItemGroup> 
     51    <Compile Include="Debug.cs" /> 
    5152    <Compile Include="Document.cs" /> 
    5253    <Compile Include="DocumentSet.cs" />